使用vsc写入
src=" " ——其中输入图片的存放地址
方法1:
<img id="light" src="D:/phpStudy/PHPTutorial/WWW/dengpao/p2.gif"><script>
var light=document.getElementById("light")
var f= false
light.onclick=function(){if (f==false){light.src="D:/phpStudy/PHPTutorial/WWW/dengpao/p1.gif"}else{light.src="D:/phpStudy/PHPTutorial/WWW/dengpao/p2.gif"}f=!f
}</script>
方法2:是在法1基础上改进
<img id="light" src="D:/phpStudy/PHPTutorial/WWW/dengpao/p2.gif" onclick="a1()"><script>var light = document.getElementById("light")var f2 =falsefunction a1() {if (f2==false) {light.src = "D:/phpStudy/PHPTutorial/WWW/dengpao/p1.gif"} else {light.src = "D:/phpStudy/PHPTutorial/WWW/dengpao/p2.gif"}f2=!f2}
运行如下:
小灯泡如下: