為什么我的倒計時到2時會自動回到5?
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title>?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <p>操作中</p>
? <p><span id="myid">5</span>秒后回到主頁</p>
? <a href="idcbgp.cn">返回 </a>
?
?
? <script type="text/javascript">?
? var n=5,t;
? function begin(){
?
? document.getElementById("myid").innerHTML=n;
? n--;?????
? if (n==0){
????
????? clearTimeout(t);
?????? window.history.go(-1);
? }
?
?? t=setTimeout("begin()",1000);
? }
?? //獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
?
?? //通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? begin();
?? </script>
</body>
</html>
能實現(xiàn)倒計時功能,但是會有2次只回到2時又重置到5了,不知道什么原因,請大神指教!
2018-09-30
同學(xué),你這個最好自己在本地測試一下,我給你測試了是沒有問題的,也沒有出現(xiàn)你說的那種情況
2018-09-27
是不是開了自動刷新了?