JavaScript定時器問題
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <div id="main">
? ? <p><strong>操作成功</strong></p>
? ? ?<span id="show">5</span>秒后跳轉(zhuǎn)
? ? <a href="javascript:showMinut();">返回</a>
? </div>
??
?
? <script type="text/javascript">
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?
? ?var num = 5;?
? ?//var t;
? ?function showMinut()
? ?{
? ? ?document.getElementById("show").innerHTML=num;
? ? ?num=num-1;
? ? ?if(num<=0)
? ? ?{
? ? ? ? ?//window.open('http://idcbgp.cn/course/list');
? ? ? ? ? location="http://idcbgp.cn";
? ? ? ? ? return;
? ? ?}
? ? ?setTimeout("showMinut()",1000);
? ?}
? ??
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ? ?function back()
? ? {
? ? ? ? window.history.back();
? ? }
?</script>?
</body>
</html>
為什么我寫的定時五秒不能自動返回指定的網(wǎng)頁?需要單擊一下 “返回”是一下 ? 然后秒數(shù)才會自動減少然后顯示指定網(wǎng)址的網(wǎng)頁
2016-10-25
自己回答吧 ? 應(yīng)該用setInterval("showMinut()",1000); 而且這一句的位置應(yīng)該是在自定義的函數(shù)體外面。