我有一个setInterval()函数,使用如下
setInterval(function(){
if(window.document.drops.isFinished()){
//I want to exit the setInterval() on executing this if
}
},1000);
Run Code Online (Sandbox Code Playgroud)
或告诉我退出的方法是什么.(在java中我们使用System.exit(0))
nic*_*elo 21
var timerId = setInterval(function(){
if(window.document.drops.isFinished()){
clearInterval(timerId);
}
},1000);
Run Code Online (Sandbox Code Playgroud)
如果if它不是函数中的最后一件事并且你想要"中断"执行,也许你想在return;之后添加一个语句clearInterval.