我可能在這盯着太久累了, 也許有人可以清除此爲我:JS:的setInterval和clearIntervals與jQuery
//scripts in whispers are setup this way.
var something = function(){
setInterval(function1,1000);
setInterval(function2,1000);
blah .. blah...
}
//function2 is the same as this one
var function1 = function(){
ajax to do something on server
blah...
blah...
}
//button to stop things from running anymore
$('.stop').live('click',function(){
clearInterval(function1);
clearInterval(function2);
return false;
}
我應該能夠停止功能1和/或2運行後 點擊按鈕是啊?出於某種原因 - 在 兩個函數內的ajax調用繼續運行並ping服務器。
感謝詹姆斯! 感謝JesseB的例子(下圖):http://stackoverflow.com/q/8251941/294895 – kenok