发布后跳转到锚点

时间:2016-01-20 07:57:26

标签: express keystonejs

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

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:''});

};

1 个答案:

答案 0 :(得分:0)

我用HTML来解决这个问题。只需将锚点放在表格的动作中。

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