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