<!DOCTYPE?html>
<html>?
<head>??
<title>瀏覽器對象</title>????
<meta?http-equiv="Content-Type"?content="text/html;?charset=gkb"/>????
</head>?
<body>??
<!--先編寫好網頁布局-->????
<p><b>操作成功</b></p>??
<p><span?id='num1'>5</span>秒后回到主頁?<a?href="history()">返回</a></p>???????
<script?type="text/javascript">?????
var?num=?document.getElementById('num1').innerHTML???
//獲取顯示秒數的元素,通過定時器來更改秒數。???
console.log(num)???
function?number(){???????
num--;???????
ocument.getElementById('num1').innerHTML=num???????
if(num==0){???????????
location.assign("http://www.xianlaiwan.cn");???????
}??????
etTimeout('number()',1000)???
}??????s
etTimeout('number()',1000)???
//通過window的location和history對象來控制網頁的跳轉。???
function?history(){???????
window.history.back()???
}?
</script>?
</body>
</html>
2018-12-17
就我看來,你的代碼有以下幾個問題。
1:17行? document寫錯了,ocument.
2:21,22行,setTimeout寫成了etTimeout
3:
<a?href="history()">返回</a></p>??
這一句里,雖然JS href標簽可以接函數,語法是href="javascript:function()",但是這種寫法不推薦:推薦寫法:href="http://www.xianlaiwan.cn" onclick="history()"。
4.你的
number()函數內,location.assign("http://www.xianlaiwan.cn");???改為window.location.assign("http://www.xianlaiwan.cn");2018-12-15
沒有上一頁吧