例如,我有几个地方使用下面的行来清除一个状态。我有一些游戏会持续10秒或更长时间,如果用户四处点击,操作可能会在不正确的时间间隔内发生。

window.setTimeout(function() { removeStatusIndicator(); }, statusTimeout);

是否有可能取消或杀死这个与一些jQuery或JavaScript代码,所以我没有这个进程徘徊?


当前回答

window.clearTimeout()应该做你想要实现的事情。

其他回答

window.clearTimeout()应该做你想要实现的事情。

var timer1 = setTimeout(function() { removeStatusIndicator(); }, statusTimeout);

clearTimeout(timer1)