准备图片
关灯
开灯
html界面,简单一点,就放两个按钮和图片
<input type="button" onclick="on()" value="开灯">
<img src="../img/关灯.png" alt="加载中..." id="1">
<input type="button" onclick="off()" value="关灯">
用onlick属性来执行点击事件
用js实现开关灯
其实开关灯就是两张图片的切换,所以只需要改换原来的img的src属性就行
let img = document.getElementById("1");
function on(){
img.src = "../img/开灯.png";
}
function off()