時間減到0秒時不跳轉,怎么辦啊?
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>? ?
? <style>
? ? ? a{color:blue;text-decoration:underline;}
? </style>
?</head>
?<body>?
? <!--先編寫好網頁布局-->
??
?<h3>操作成功</h3>
<p><span id="s">5</span>秒后回到主頁 <a herf="javascript:tiaozhuan()">返回</a></p>
? <script type="text/javascript">??
? ?var num=5;
? ?var t= setInterval( function sub(){
? ? ? ? num--;
? ? ? ? document.getElementById("s").innerHTML=num;
? ? ? ? if(num==0){
? ? ? ? ? window.location.href("http://www.xianlaiwan.cn");?
? ? ? ? ? clearInterval(t);
? ?}
? ?},1000);
? ?
? ? ? function tiaozhuan(){
? ? ? ?window.location.back();
? ?}
? ? ?
? ?//獲取顯示秒數的元素,通過定時器來更改秒數。
? ?
? ?//通過window的location和history對象來控制網頁的跳轉。
? ?
?</script>?
</body>
</html>
2019-02-10
用
而不要用 window.location.href
2019-02-26
href 是 location 的屬性,而不是方法,所以要用的話應該這樣寫: location.href="http://www.xianlaiwan.cn";?