var num=0; function startCount() { document.getElementById('count').value=num; num=num+1; setTimeout("startCount()",1000); if(num==10){ break;//报错 } } setTimeout("startCount()",1000);
配合使用需要这样:
a = setTimeout("startCount()",1000); clearTimeout(a);
clearTimeout()
记录timeid
var timeId = setTimeout(startCount,1000);
clearTimeout(timeId)
clearTimeout()