為什么我的計時器就使用了一次,不應(yīng)該是1000,就執(zhí)行一次嗎
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <p>操作成功</p>
? <p><span id = "sp">5</span>秒后回到主頁</p>
? <a href="">返回</a>
?
? <script type="text/javascript"> ?
?var i = document.getElementById("sp").innerHTML;
?function time(){
? ? for(i;i>=0;i--){
? ? i--;
? ? document.getElementById("sp").innerHTML = i;
? ? if(i==0){
? ? ? ? ?window.open("http://idcbgp.cn");
? ? ?}
? ? }
?}
?setInterval(time(),1000);
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ?
?</script>?
</body>
</html>
2018-09-26
setInterval(time(),1000);語句中要么用 time,直接引用函數(shù),或用"time()"引用函數(shù)。
2018-09-25
<!DOCTYPE html>
是這個代碼
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <p>操作成功</p>
? <p><span id = "sp">5</span>秒后回到主頁</p>
? <a href="">返回</a>
?
? <script type="text/javascript"> ?
?var i = document.getElementById("sp").innerHTML;
?function time(){
? ??
? ? i--;
? ? document.getElementById("sp").innerHTML = i;
? ? if(i==0){
? ? ? ? ?window.open("http://idcbgp.cn");
? ? }
? ??
?}
?setInterval(time(),1000);
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ?
?</script>?
</body>
</html>