關于num賦初始值問題
?var num=5;
? ? var num=document.getElementById("second").innerHTML;
兩個的顯示效果賦5的時候,計數可能會到-1,-2,才會跳轉;第二個又正常跳轉。
這兩個有什么不一樣的么?
?var num=5;
? ? var num=document.getElementById("second").innerHTML;
兩個的顯示效果賦5的時候,計數可能會到-1,-2,才會跳轉;第二個又正常跳轉。
這兩個有什么不一樣的么?
2016-09-01
舉報
2016-11-17
這不是第八章的練習嗎?
2016-09-03
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網頁布局-->
? <span id="count">5</span>秒后返回主頁<a href="javascript:" onclick="goback()">返回</a>
??
?
? <script type="text/javascript">?
?
? ?//獲取顯示秒數的元素,通過定時器來更改秒數。
? ?var num=parseInt(document.getElementById("count").innerHTML); ??
? ?var i= setInterval("count()",1000);
? ?function count()
? ?{
? ? ? ?if(num>0)
? ? ? ?{
? ? ? ? ? ? document.getElementById("count").innerHTML = num;
? ? ? ? ? ? num--; ? ? ? ? ? ?
? ? ? ?}
? ? ? ?else
? ? ? ?{
? ? ? ? ? ? window.location="http://www.xianlaiwan.cn";
? ? ? ? ? ? //location.assign("http://www.xianlaiwan.cn");
? ? ? ?}
? ? }
? ??
? ?//通過window的location和history對象來控制網頁的跳轉。
? ? function goback()
? ? { ? ? ??
? ? ? ? clearInterval(i); ? ?
? ? ? ? window.location.href ="http://www.xianlaiwan.cn";
? ? }
? ?
?</script>?
</body>
</html>
2016-09-01
給你參考一下我的思路吧: