慕蓋茨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貢獻1條經驗 獲得超2個贊
f (box.style.backgroundColor="aqua") 改為f (box.style.backgroundColor=="aqua") ,你寫的是個賦值語句,雙等或恒等(3個等號)才是判斷語句


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