jQuery:单击按钮,单击事件触发两次或多次 [英] jQuery: Single button click, click event firing two or more times
问题描述
您可能会发生问题,因为您将多个相同的处理程序分配给点击事件。我建议你检查你分配处理程序的行不是无意中被多次调用。另一个解决方案可能是这样的一个取消绑定的呼叫:
$(#myButton)。unbind(click) 。点击(将myHandler);
但是没有看到我只是猜测的代码。
I have HTML input and button elements. I use the buttons to submit forms, open secondary windows, etc. The problem is, a single click is turning into 2 (and sometimes many more) form submissions, or opening two additional browser windows. I've reproduced the problem in multiple web browsers. I've tried switching jQuery versions and that didn't change anything. What could be causing this sort of thing to happen?
Your problem may be happening because you are assigning the same handler to the click event multiple times. I suggest you check that the line where you assign the handler is not being called multiple times inadvertently. Another solution could be a call to unbind first like this:
$("#myButton").unbind("click").click(myHandler);
But without seeing some code I'm just guessing.
这篇关于jQuery:单击按钮,单击事件触发两次或多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!