【问题标题】:Jump to anchor after post发布后跳转到锚点
【发布时间】:2016-01-20 16:24:05
【问题描述】:

我正在使用 Keystone.js,并在页面底部放置了一个查询表单。它基本上只是 Keystone Generator 为 contact.js 视图提供的示例的副本。我可以让它正确提交并显示错误,但是在提交后浏览器将我置于页面顶部。发布到 Enquiry 后,有没有办法跳转到页面上的锚点?

var keystone = require('keystone');
var Enquiry = keystone.list('Enquiry');

exports = module.exports = function(req, res) {

    var view = new keystone.View(req, res),
        locals = res.locals;

    // locals.section is used to set the currently selected
    // item in the header navigation.
    locals.section = 'home';
    locals.enquiryTypes = Enquiry.fields.enquiryType.ops;
    locals.formData = req.body || {};
    locals.validationErrors = {};
    locals.enquirySubmitted = false;

    // On POST requests, add the Enquiry item to the database
    view.on('post', { action: 'contact' }, function(next) {

        var newEnquiry = new Enquiry.model(),
            updater = newEnquiry.getUpdateHandler(req);

        updater.process(req.body, {
            flashErrors: true,
            fields: 'name, email, phone, enquiryType, message',
            errorMessage: 'There was a problem submitting your form:'
        }, function(err) {
            if (err) {
                locals.validationErrors = err.errors;
            } else {
                locals.enquirySubmitted = true;
            }
            next();
        });

    });


    // Render the view
    view.render('index', {layout:''});

};

【问题讨论】:

    标签: express keystonejs


    【解决方案1】:

    我用 HTML 解决了这个问题。只需将锚点放在表单的操作中即可。

    <form method="post" action="#contact">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      相关资源
      最近更新 更多