為什么我的計(jì)時(shí)器就使用了一次,不應(yīng)該是1000,就執(zhí)行一次嗎
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁(yè)布局-->
? <p>操作成功</p>
? <p><span id = "sp">5</span>秒后回到主頁(yè)</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ù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ?
?</script>?
</body>
</html>
2018-09-26
setInterval(time(),1000);語(yǔ)句中要么用 time,直接引用函數(shù),或用"time()"引用函數(shù)。
2018-09-25
<!DOCTYPE html>
是這個(gè)代碼
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁(yè)布局-->
? <p>操作成功</p>
? <p><span id = "sp">5</span>秒后回到主頁(yè)</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ù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ?
?</script>?
</body>
</html>