為什么不可以使用while循環?
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>? ?
?</head>
?<body>
? <!--先編寫好網頁布局-->
? <h1>加載成功</h1>
? <p id="pid"></p>
? <button onclick="back1()">返回</button>
? <script type="text/javascript">??
? var num = 5;
? var i;
? function ref(){
? ? ? while(num>0){
? ? ? ? ? document.getElementById("pid").innerHTML = num +"秒后跳轉";
? ? ? ? ? num--;
? ? ? ? ? i = setTimeout(ref,1000);
? ? ? ? ?}
? ? ? ? ? clearTimeout(i);
? ? ? ? ? location.assign("http://www.xianlaiwan.cn");
? }
? ref();
? function back1(){
? ? ? window.history.back();
? }
? ?//獲取顯示秒數的元素,通過定時器來更改秒數。
? ?//通過window的location和history對象來控制網頁的跳轉。
? ?
?</script>?
</body>
</html>
只閃了一下立馬跳轉了
2018-12-25
循環與定時器的區別就是,循環是秒執行。。定時器是你自己設置,你可以設置1秒執行,2秒執行等等。。但循環就是系統直接瞬間執行完。。望采納