iT邦幫忙

1

javascript無法改button的初始值

我想要改javascript的初始值,但是卻無法改,bt1的value改了之後,再按一次button還是不會跑else的部份,以下是程式碼,麻煩大家看看

看更多先前的討論...收起先前的討論...
馬克 iT邦研究生 3 級 ‧ 2017-01-02 15:39:53 檢舉
呃看不到
晨勤 iT邦新手 4 級 ‧ 2017-01-02 15:51:14 檢舉
不好意思,沒貼好,已經修正了,順便給大家看看
<script language="javascript">
var bt=6;
function fun1()
{
if(bt=9)
{
document.getElementById("bt1").value="不要按我";
alert(bt);
bt=6;
alert(bt);
}
else
{
alert(bt);
document.getElementById("bt1").value="按我";
bt=9;
alert(bt);
return bt;
}
}
</script>
<body>
<form id="f1">
<input type="button" id="bt1" value="不要按我" onclick="fun1()"/>
</form>
<span id="t1"></span>
</body>
晨勤 iT邦新手 4 級 ‧ 2017-01-02 15:52:33 檢舉
奇怪,早上怎麼試都試不出來,睡個覺,下午改一下就可以了,卻忘了當初錯在哪....@#%&
if(bt=9) <== 你都不覺得什麼地方怪怪的嗎?
晨勤 iT邦新手 4 級 ‧ 2017-01-03 04:54:58 檢舉
請問....是什麼地方怪怪的??
allpower iT邦新手 5 級 ‧ 2017-01-03 05:48:17 檢舉
==
if(bt=9) <== 你都不覺得什麼地方怪怪的嗎?
這是第二次跟你說了!
請「認真仔細想想」那裡怪怪的。
weiclin iT邦高手 4 級 ‧ 2017-01-03 09:35:03 檢舉
建議去看一下 if 裡面的判斷式怎麼寫..
kgame iT邦新手 4 級 ‧ 2017-01-03 12:11:38 檢舉
==
晨勤 iT邦新手 4 級 ‧ 2017-01-04 08:00:31 檢舉
謝謝各位大德指正,小弟知道錯了...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
MichaelQQ
iT邦新手 5 級 ‧ 2017-01-03 11:40:12
最佳解答

判斷式那邊有問題

if (bt == 9) ...
or
if (bt === 9) ...

Example

我要發表回答

立即登入回答