我的跳轉(zhuǎn)為什么直接從4秒跳到2秒
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title>??
? <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>? ?
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <h1>操作成功</h1>
? <p><span id="one"></span>秒后回到主頁面<a href="#" onclick="goback()">返回</a><p>
? <script type="text/javascript">??
? ?//獲取顯示秒數(shù)的元素,通過定時(shí)器來更改秒數(shù)。
? ?var sum=5;
function ms(){
if(sum!=0){
document.getElementById('one').innerText=sum;
sum--;
var i=setInterval(ms,1000);
}else{
clearInterval(i);
location.assign("http://idcbgp.cn");
}
}
ms();
function goback(){
window.history.back();
}
? ?//通過window的location和history對(duì)象來控制網(wǎng)頁的跳轉(zhuǎn)。? ?
?</script>?
</body>
</html>
2019-08-28
你直接像我這樣寫。。你下次寫代碼定時(shí)器不要放在函數(shù)里面調(diào)用函數(shù)...