不會(huì)自動(dòng)返回,而且秒數(shù)直接減少到0了
<!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><br>
? <div><span id="second">5</span>秒后回到主頁(yè) <a href="#" onclick="way()">返回</a>
? </div>
?
?
?
? <script type="text/javascript">?
?
?? //獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
?
? var i=5;
?? function clock(){
??????? document.getElementById("second").innerHTML=i;
?????? i=i-1;
?? if(i=0){
?????? window.location.assign("http://idcbgp.cn");
?? }
?? }
?
?? setInterval("clock()",1000);
?? //通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
?? function way(){
?????? window.history.back();
?? }
??
?</script>
</body>
</html>
2018-08-10
if(i=0) 錯(cuò)了? 是 i==0
2018-08-04
<!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><br>
? <div><span id="second">5</span>秒后回到主頁(yè) <a href="#" onclick="way()">返回</a>
? </div>
?
??
?
? <script type="text/javascript">??
?
? ?//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ? window.onload =function(){
? ? setInterval("clock()",1000);
? ? ?}
? ? ?var i=5;
? ? function clock(){
? ? ? ?document.getElementById("second").innerHTML= i;
? ? ? ?i--;? //直接i--就好了,不用想太多!
? ? ? ?if(i<=0){
? ? ? ?window.location.assign("http://idcbgp.cn");
? ? ? ?}?
? ? ?}
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ?function way(){
? ? ? ?window.history.back();
? ?}
? ?
?</script>?
</body>
</html>