代码之家  ›  专栏  ›  技术社区  ›  Al C

帖子后跳转到锚

  •  0
  • Al C  · 技术社区  · 10 年前

    我在用Keystone。js和我在页面底部放了一张查询表。它基本上只是Keystone Generator为联系人提供的示例的副本。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 回复  |  直到 10 年前
        1
  •  0
  •   Al C    10 年前

    我用HTML解决了这个问题。只需要在表单的动作中添加锚。

    <form method="post" action="#contact">
    
    推荐文章