如果将按钮放入SubmitHandler,为什么我的按钮在jquery中单击两次? [英] Why does my button click twice in jquery if I put it in submitHandler?
问题描述
我有一个简短的表格,您可以在这里看到它 http://jsfiddle.net/azxpckg5/1/
I have a short form, you can see it here http://jsfiddle.net/azxpckg5/1/
,我有一个问题-再现它的方法是单击save
按钮.然后将出现另一个名为submit
的按钮.当用户单击它时-它消失了,就可以了.但是,当用户重复此过程时(再次单击save
和submit
-他可以看到最后一次单击重复了两次.我相信错误可能在这里:
and I have a problem - the way to reproduce it is to click the save
button. Then there will appear another button called submit
. when user clicks it - it disappears and it's fine. But when user repeats this procedure (clicks save
again and submit
again - he can see that the last click was repeated twice. I believe the error might be somewhere here:
submitHandler: function (form) {
alert("here!");
$(".overlay-boxify2").toggleClass("open");
$('#submitcForm').click(function() {
//
$(".overlay-boxify2").toggleClass("open");
alert("hegdsgsd");
});
return false;
}
但是说实话,我不知道如何解决它,可能是什么问题.你能帮我吗?
but to be honest I don't know how to fix it and what can be the issue. Can you help me with that?
推荐答案
问题是因为您要在每次提交表单时将另一个click事件处理程序附加到#submitcForm
按钮上(单击#saveBtn
时会发生这种情况) .将点击处理程序移到validate()
调用之外,您的代码将按您的要求工作.
The issue is because you're attaching another click event handler to the #submitcForm
button on every submission of the form (which happens when #saveBtn
is clicked. Move the click handler outside of the validate()
call and your code will work as you require.
$('#invoiceForm').validate({
// settings...
});
$('#submitcForm').click(function () {
$(".overlay-boxify2").toggleClass("open");
});
这篇关于如果将按钮放入SubmitHandler,为什么我的按钮在jquery中单击两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!