關(guān)于num賦初始值問(wèn)題
?var num=5;
? ? var num=document.getElementById("second").innerHTML;
兩個(gè)的顯示效果賦5的時(shí)候,計(jì)數(shù)可能會(huì)到-1,-2,才會(huì)跳轉(zhuǎn);第二個(gè)又正常跳轉(zhuǎn)。
這兩個(gè)有什么不一樣的么?
?var num=5;
? ? var num=document.getElementById("second").innerHTML;
兩個(gè)的顯示效果賦5的時(shí)候,計(jì)數(shù)可能會(huì)到-1,-2,才會(huì)跳轉(zhuǎn);第二個(gè)又正常跳轉(zhuǎn)。
這兩個(gè)有什么不一樣的么?
2016-09-01
舉報(bào)
2016-11-17
這不是第八章的練習(xí)嗎?
2016-09-03
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫(xiě)好網(wǎng)頁(yè)布局-->
? <span id="count">5</span>秒后返回主頁(yè)<a href="javascript:" onclick="goback()">返回</a>
??
?
? <script type="text/javascript">?
?
? ?//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
? ?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://idcbgp.cn";
? ? ? ? ? ? //location.assign("http://idcbgp.cn");
? ? ? ?}
? ? }
? ??
? ?//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
? ? function goback()
? ? { ? ? ??
? ? ? ? clearInterval(i); ? ?
? ? ? ? window.location.href ="http://idcbgp.cn";
? ? }
? ?
?</script>?
</body>
</html>
2016-09-01
給你參考一下我的思路吧: