為什么定時(shí)器不動(dòng)呢
<!DOCTYPE html>
<html>
<head>
<title>瀏覽器對(duì)象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
? <!--先編寫(xiě)好網(wǎng)頁(yè)布局-->
? <h1>操作成功</h1>
? <span id="second">5</span>秒后返回主頁(yè)<a href="javascript::window.history.back()">返回</a>
? <script type="text/javascript"> //獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。 //通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
?? var time= document.getElementById("second").innerHTML;
??? ?
??? var i=setInterval("if(time>1){
????????? document.getElementById('second').innerHTML=--time;
????????? }else{
????????????? location.assign(
????????????????? "http://idcbgp.cn");
????????? }",1000);
?? ?
? </script>
? </body>
? </html>
2017-04-26
你的雙引號(hào)弄錯(cuò)了,在雙引號(hào)里面應(yīng)該用單引號(hào)包裹,不過(guò)也不推薦這樣寫(xiě)setInterval里面的語(yǔ)句,要是封裝成一個(gè)function,要么直接function(){//這里面寫(xiě)代碼}