為什么只有5,4,3,1,0秒,第2秒為什么不顯示呢
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網頁布局-->
<p>操作成功</p>
<p><span id="txt">5</span> 秒后回到主頁<a href="javascript:Return()">返回</a>
</p>
? <script type="text/javascript"> ?
? ?function Return(){
? ? window.history.back();
? ? }
? ??
? ? var num=5;
? ? function OpenbyClock(){
? ? ? ? if(num>0){
? ? ? ? ? ? num=num-1;
? ? ? ? ? ? document.getElementById("txt").innerHTML=num;
? ? ? ? ? ? setInterval("OpenbyClock()",1000);
? ? ? ? }
? ? ? ? else{
? ? ? ? location.assign("https://www.baidu.com/");
? ? ? ? }
? ? }
? ? ?setTimeout("OpenbyClock()",1000);
? ?//獲取顯示秒數的元素,通過定時器來更改秒數。
? ?//通過window的location和history對象來控制網頁的跳轉。
? ?
?</script>?
</body>
</html>
2016-12-01
知道了,setInterval全都改成setTimeout就可以了。