setInterval("count()",1000)改成setTimeout(”count()",1000)為什么就不行
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁(yè)布局-->
? <h1>操作成功</h1>
<span id="second" >5</span>
? <span >秒后回到主頁(yè)</span>
? <a href="javascript:history.back()">返回</a>
??
??
?
? <script type="text/javascript"> ?
? ? var num=document.getElementById("second").innerHTML;
? ?//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
??
? ? function count()
? ? {
? ? ? ? num--;
? ? ? ? document.getElementById("second").innerHTML=num;
? ? ? ? if(num==0)
? ? ? ? {
? ? ? ? ? ? location.assign("http://idcbgp.cn");
? ? ? ? }
? ? }
? ? setInterval("count()",1000);
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ? function back()
? ? {
? ? ? ?window.history.go();
? ?}
? ?
?</script>?
</body>
</html>
2016-12-12
可以用
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <p style="font-size:30px;">操作成功</p>
? <div>
? ? ? ?<span id="aa">5</span>秒后返回主頁(yè)
? ? ? <a href="javascript:history.back()">返回</a>
? </div>
??
? <script type="text/javascript"> ?
?var num=5;
?function count(){
? ? document.getElementById("aa").innerHTML=num;
? ? ?num--; ? ?
? ? ?if(num==-1) window.location.href="widcbgp.cn";
? ? ?setTimeout("count()",1000);
? ? ?}
?count(); ?
?</script>?
</body>
</html>
2016-12-08
setTimeout()方法只執(zhí)行一遍,不會(huì)循環(huán)使用里面的count方法,只會(huì)執(zhí)行一遍