【发布时间】:2022-01-09 12:43:59
【问题描述】:
我不明白我在这里做错了什么,我尝试调试代码,但我没有发现我在这里做错了什么。 我尝试使用 java 脚本替换 html 中的图像,我希望能对我的问题提供一些有用的帮助
HTML 代码:
<img id = "lamp" src = "js/Capture.PNG"/>
<!--make a button to turn on or off the lamp in this case -->
<button id = "off" name = "offf" onclick="change_attribute()" >Turn off the light</button>
<button id = "on" name = "offf" onclick="change_attribute()"> turn on the light </button>
Javacript 代码:
function change_attribute() {
var x = document.getElementsByName("offf");
if (x.id === "off")
{
document.getElementById('off').src = "js/Capture.PNG/";
}
else
{
document.getElementById('on').src = 'js/Capture2.PNG/'
}
}
【问题讨论】:
-
不确定 C# 的相关性!
标签: javascript c# html css