我有一个 asp.net 表单,它允许用户提交一个注册表单,该注册表单使用 Web 服务在 SharePoint 列表上内部发送/存储所有这些值,因此提交页面处理时间比正常情况稍长一些表格。
平均在页面重定向到感谢页面之前,用户往往会再次点击提交按钮,从而导致同一条记录的多次提交。
请建议一种限制此提交的方法,在单击按钮时我使用 jquery 函数进行数据验证,我尝试使用 btn.disable = true 方法,但是一旦到达 else block (通过验证后)这就是disable = true代码所在的地方)在阅读btn.disable = true语句后它不会提交表单。
请高手指点迷津。
提前致谢。
最佳答案
查看 Nathan Long 的插件:https://stackoverflow.com/a/4473801/1414562
{修改为允许在输入更改时重新提交表单}
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function() {
var $form = $(this);
$form.on('submit',function(e){ //on here instead of bind
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
$form.data('submitted', true);
}
}).find('input').on('change',function(){
$form.data('submitted',false);
});
// Keep chainability
return this;
};
像这样使用它:
$('form').preventDoubleSubmission();
关于c# - 如何限制用户重复提交表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16364101/