用clearinterval制作定時器,暫停失敗,找不到問題出在哪.
<body>
<button id="stop">stop</button>
<button id="strat">strat</button>
<script>
var arr=setInterval(function()
{
var a=new Date();
year=a.getFullYear();
mouth=a.getMonth();
day=a.getDate();
hour=a.getHours();
minute=a.getMinutes();
second=a.getSeconds();
str=year+"-"+mouth+"-"+day+" "+hour+":"+minute+":"+second;
document.title=str;},1000)
b=document.getElementById('stop');
b.onclick=function(){
clearInterval(a);
}
c=document.getElementById('strat');
c.onclick=function(){
setInterval(a,1000);
}
</script>
</body>
檢查了好久,都沒看出問題在哪?剛做完的時候是可以暫停的,關掉再次執(zhí)行就不行了。我把代碼發(fā)給一個朋友,他說他可以暫停,就很神奇。
2020-06-02
不會你這樣的寫法,沒明白你的函數(shù)是怎么做的,就改了下,不是回答,只是交流,哈哈哈
2020-04-07
clearInterval(a);這裏面應該寫arr,你定時器沒有這個a怎么結束呢
2020-03-18
document.title=str;},1000),這個地方寫錯了