2
我希望將圖片從燈泡關閉更改爲燈泡上的兩個按鈕的點擊。我在W3schools中看到過類似的例子,但是,我無法看到代碼之間的區別。請幫忙。我的代碼有什麼問題?(使用javascript更改圖片)
<!doctype html>
<html>
<body>
<script>
function light(switch){
var pi;
if(switch == 0){
pi = "pic_bulboff.gif"
}
<!--this is if the switch value is zero-->
else{
pi = "pic_bulbon.gif"
}
<!--this is if switch value is anything else including 1-->
document.getElementById('sw').src = pi;
}
</script>
<img id="sw" src="pic_bulboff.gif">
<button onclick="light(0)">Light off</button>
<button onclick="light(1)">Light on</button>
</body>
</html>
謝謝!得到它了。 –