post 后跳转到锚点
Jump to anchor after post
我正在使用 Keystone.js,我在页面底部放置了一个查询表。它基本上只是 Keystone 生成器为 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:''});
};
我用 HTML 弄明白了。只需将锚点放在表单的操作中即可。
<form method="post" action="#contact">
我正在使用 Keystone.js,我在页面底部放置了一个查询表。它基本上只是 Keystone 生成器为 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:''});
};
我用 HTML 弄明白了。只需将锚点放在表单的操作中即可。
<form method="post" action="#contact">