js 8-17練習(xí)(網(wǎng)頁跳轉(zhuǎn)和返回)
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <h3>操作成功</h3>
? <p><span id="wholeTime">5</span>秒后回到主頁 ?<a href="javascript:void(0)" onclick="back()">返回</a></p>
??
??
?
? <script type="text/javascript"> ?
?
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?var time =new Date();
? ?var t=document.getElementById("wholeTime").innerHTML;
? ?function daojishi()
? ?{
? ? ? ?if(t>0)
? ? ? ?{
? ? ? ? ? ?t--;
? ? ? ? ? ?document.getElementById("wholeTime").innerHTML=t;
? ? ? ?}
? ? ? ?else?
? ? ? ?window.open("http://idcbgp.cn/");
? ?}
? ?var a=window.setInterval(daojishi,1000);
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ?function back()
? ?{
? ? ? ?window.history.back();
? ?}
? ?
?</script>?
</body>
</html>
這樣寫為什么會不停的打開網(wǎng)頁啊?求大神指導(dǎo)
2017-09-27
你沒有clearInterval啊 所以他每秒都會執(zhí)行一次
2017-09-12
與同問
2017-09-12
function daojishi()
? ?{
? ? ? ?if(t>0)
? ? ? ?{
? ? ? ? ? ?t--;
? ? ? ? ? ?document.getElementById("wholeTime").innerHTML=t;
? ? ? ?}
? ?}
? ?var a=window.setInterval(daojishi,1000);
? ?window.open("http://idcbgp.cn/");
else轉(zhuǎn)到頁面這句會在i小于0后一直執(zhí)行,然后就會不停地打開頁面.這樣改一下就可以了
2017-09-12
t是HTML格式 t>0 為false,需先使用parseInt()函數(shù)將字符串轉(zhuǎn)為整數(shù)