带有setInterval无休止的jQuery Mousdown [英] JQuery mousdown with setInterval endless

查看:123
本文介绍了带有setInterval无休止的jQuery Mousdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是指这个问题.

此刻,我正在使用此答案,但是我仍然可以欺骗该代码,因此赢得了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆