例如,如果我有以下代码:
$("#divTest").append(variable);
预期的目标是单击按钮后显示一条信息,如何处理不耐烦或感觉需要在执行代码之前多次单击(从而生成多个副本)的用户?
如果需要的话我会澄清。
谢谢!
最佳答案
看看 jQuery .one
功能。这只会允许点击处理程序使用一次。
$("#button").one("click",function() { /* -- Your code here -- */ });
<小时/>
或者,如果按钮实际上是 input
或 button
标记,您可以设置 disabled
属性。以下是来自 Mozilla Developer Network (MDN) 的更多信息关于disabled
属性。
This Boolean attribute indicates that the form control is not available for interaction. In particular, the click event will not be dispatched on disabled controls. Also, a disabled control's value isn't submitted with the form.
关于jquery - 在 jQuery 中,如何防止多次点击多次执行我的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16301455/