為什么我的倒計(jì)時(shí)從5直接跳到-1也不跳轉(zhuǎn)主頁(yè)?
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>? ?
?</head>
?<body>
? <!--先編寫(xiě)好網(wǎng)頁(yè)布局-->
<p>操作成功</p>
? <span id="seconds">5</span>
? <span>秒后回到主頁(yè)</span>
? <a href="javascript:before()">返回</a>
? <script type="text/javascript">??
? ? function before() {? ?
? ? ? ? window.history.back();
? ? }
? ??
? ?//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ? var num = document.getElementById("seconds").innerHTML;
? ? function backToMain() {
? ? ? ? if(num=0) {
? ? ? ? ? ? window.location.assign("idcbgp.cn");
? ? ? ? }
? ? ? ? num = num-1;
? ? ? ? document.getElementById("seconds").innerHTML = num;
? ? }
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ?setInterval("backToMain()", 1000);
?</script>?
</body>
</html>
2020-03-13
if(num=0)少了個(gè)等號(hào)if(num==0)