带有setInterval无休止的jQuery Mousdown [英] JQuery mousdown with setInterval endless
问题描述
我的问题是指这个问题.
此刻,我正在使用此答案,但是我仍然可以欺骗该代码,因此赢得了clearInterval
不要停止.在按住鼠标左键的同时,我只需按一下右键即可打开上下文菜单.现在没有叫clearInterval
.
At the moment I am using this answer, but I still can trick that code, so the clearInterval
won't stop. While holding my left mouse button I simple press the right one to open the contextmenu. Now the clearInterval
wasn't called.
如果我将contextmenu
事件添加到clicker
,并带有clearInterval
,则该事件会被调用,但不会清除间隔.
If I add the contextmenu
event to the clicker
, with a clearInterval
it does get called, but it won't clear the interval.
See this demo
推荐答案
向mousedown
事件添加clearInterval()
:
clicker.mousedown(function() {
clearInterval(timeout);
timeout = setInterval(function() {
clicker.text(count++);
}, 500);
return false;
});
这将在上下文菜单中触发,并且将阻止多个计时器一次运行.
That will be triggered on the context menu, and it will prevent multiple timers from running at once.
这篇关于带有setInterval无休止的jQuery Mousdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!