為什么不可以使用while循環(huán)?
<!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>
? <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 +"秒后跳轉(zhuǎn)";
? ? ? ? ? num--;
? ? ? ? ? i = setTimeout(ref,1000);
? ? ? ? ?}
? ? ? ? ? clearTimeout(i);
? ? ? ? ? location.assign("http://idcbgp.cn");
? }
? ref();
? function back1(){
? ? ? window.history.back();
? }
? ?//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ?
?</script>?
</body>
</html>
只閃了一下立馬跳轉(zhuǎn)了
2018-12-25
循環(huán)與定時(shí)器的區(qū)別就是,循環(huán)是秒執(zhí)行。。定時(shí)器是你自己設(shè)置,你可以設(shè)置1秒執(zhí)行,2秒執(zhí)行等等。。但循環(huán)就是系統(tǒng)直接瞬間執(zhí)行完。。望采納