js定时器暂停、重启

var i = 0;
var timer;
var start = function(){
console.log("start");
timer = setInterval( function(){
console.log( i++ )}, 1000)
} ;
var clear= function () {
console.log("clear");
clearInterval(timer);
//setTimeout(start,2000) //重启
}
setTimeout(clear,5000) start();

你可能感兴趣的:(js定时器暂停、重启)