我有一个setInterval()函数,使用如下
setInterval(function(){
if(window.document.drops.isFinished()){
//I want to exit the setInterval() on executing this if
}
},1000);
或者告诉我
退出的方法是什么。(在java中我们使用System.exit(0))
答案 0 :(得分:21)
var timerId = setInterval(function(){
if(window.document.drops.isFinished()){
clearInterval(timerId);
}
},1000);
如果if
它不是函数中的最后一件事而你想“破坏”执行,也许你想在return;
之后添加clearInterval
语句。 / p>