防止jQuery中的双表单提交 [英] Prevent double form submission in jQuery
问题描述
我有一个用户用来输入有关发布信息的表单。完成后,单击保存进行更新。但是,在一些罕见的情况下(15,000条记录中有10条),用户双击了保存按钮并导致双重表单提交重复发布项目。
I have a form that users use to input information about a posting. When complete they click 'Save' to update. However, in some rare cases (10 in 15,000 records) the user has double clicked the save button and caused a double form submission duplicating items for the posting.
我尝试过使用这是为了防止它:
I tried using this to prevent it:
$('input[type=submit]').click(function(){
$('input[type=submit]').attr('disabled',true);
//return true;
});
但问题是,它在Safari / Firefox等中完美运行,但在Internet上不起作用资源管理器8(可能不适用于6& 7)
But the problem with this, it works perfectly in Safari / Firefox etc, but does not work in Internet Explorer 8 (and probably not for 6 & 7)
当我在IE8中按保存时,该按钮被禁用,就是这样,根本没有表单提交。
When I press save in IE8, the button is disabled and that's it, no form submission at all.
(我尝试过但没有返回true;)
(I tried it with and without return true;)
推荐答案
我不确定这是一个完整的猜测,但它可能取决于你的选择器。请改为:
I'm not sure so this is a complete guess, but it maybe up to your selector there. Try instead:
$('input:submit').click(function() {
$(this).attr('disabled', true);
});#
你也可以尝试拦截提交事件
本身:
You may also try to intercept the submit event
itself:
$('form').bind('submit', function(e) {
$(this).find('input:submit').attr('disabled', 'disabled');
});
这篇关于防止jQuery中的双表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!