慕蓋茨1331153
2018-07-05 15:12:12
? ? <div class="box" id="box"></div>? ? <button onclick="myfunction()">按鈕</button>? ? <script>? ? function myfunction() {? ? var box = document.getElementById("box");? ? ? ? if (box.style.backgroundColor="aqua")?? ? ? ? ? ? {? ? ? ? ? ? ? ? box.style.backgroundColor="red";? ? ? ? ? ? }? ? ? ? else {? ? ? ? ? ? box.style.backgroundColor="black";? ? ? ? }? ? }? ? </script>
4 回答

qq_y見你很幸福_0
TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超2個(gè)贊
f (box.style.backgroundColor="aqua") 改為f (box.style.backgroundColor=="aqua") ,你寫的是個(gè)賦值語句,雙等或恒等(3個(gè)等號(hào))才是判斷語句


慢l慢
TA貢獻(xiàn)22條經(jīng)驗(yàn) 獲得超3個(gè)贊
box.style.backgroundColor="aqua",一個(gè)“=”是賦值符號(hào),用“==”或者“===”才是判斷是否相等的符號(hào)。
你改成box.style.backgroundColor==="aqua"試試
添加回答
舉報(bào)
0/150
提交
取消