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