JQuery 设置间隔无限的mousdown

JQuery mousdown with setInterval endless

我的问题是指 this 问题。

目前我正在使用 this answer,但我仍然可以欺骗该代码,所以 clearInterval 不会停止。在按住鼠标左键的同时,我只需按右键即可打开上下文菜单。现在 clearInterval 没有被调用。

如果我将 contextmenu 事件添加到 clicker,带有 clearInterval 它会被调用,但不会清除间隔。

See this demo

clearInterval() 添加到 mousedown 事件:

clicker.mousedown(function() {
  clearInterval(timeout);
  timeout = setInterval(function() {
    clicker.text(count++);
  }, 500);

  return false;
});

这将在上下文菜单中触发,它会阻止多个计时器同时 运行。

Fiddle