<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title><script>var flag = false;//代表关闭function fun(){var light = document.getElementById("light");if(flag){light.src="img/off.gif";flag = false;}else{light.src="img/on.gif";flag = true;}}</script></head><body><img id="light" onclick="fun()" src="img/off.gif" alt=""></body></html>
如果觉得《js小案例:控制电灯开关》对你有帮助,请点赞、收藏,并留下你的观点哦!