var started = false;
function start() {
var timer;
if(started === false) {
timer = setInterval(decrease, 1000);
started = true;
} else {
clearInterval(timer);
console.log("Should Clear");
}
}
setInterval可以工作,但是當我再次運行該函數時,它會在控制檯中打印它應該被刪除。但事實並非如此。clearInterval不起作用
只需刪除線VAR定時器; – Rocker1985
我推薦閱讀http://stackoverflow.com/q/111102/497418 – zzzzBov