亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于num賦初始值問題

?var num=5;

? ? var num=document.getElementById("second").innerHTML;

兩個的顯示效果賦5的時候,計數可能會到-1,-2,才會跳轉;第二個又正常跳轉。

這兩個有什么不一樣的么?


正在回答

3 回答

這不是第八章的練習嗎?

0 回復 有任何疑惑可以回復我~

<!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>


0 回復 有任何疑惑可以回復我~

給你參考一下我的思路吧:

<!DOCTYPE?html>
<html>
????<head>
????????<title>瀏覽器對象</title>
????????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"/>
????</head>
????<body>
????????<h6>操作成功</h6>
????????<span?id="t">5</span>秒后回到主頁?<a?href="#"?onclick="goback()">返回</a>
????????<script?type="text/javascript">
????????????var?num?=?5;
????????????function?count()?{
????????????????document.getElementById("t").innerText?=?num;
????????????????num--;
????????????????setTimeout("count()",1000);
????????????}
????????????setTimeout("count()");
????????????function?goback()?{
????????????????clearTimeout(i);
????????????????window.location="http://www.baidu.com/";
????????????}
????????????var?i?=?setTimeout("window.location='http://www.xianlaiwan.cn/'",?5000);
????????</script>
????</body>
</html>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于num賦初始值問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號