简单教程
提交运行
代码编辑器:
<script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bulbon")) { element.src="/static/i/javascript/basic/pic_bulboff.gif"; } else { element.src="/static/i/javascript/basic/pic_bulbon.gif"; } } </script> <img id="myimage" onclick="changeImage()" src="/static/i/javascript/basic/pic_bulboff.gif" width="100" height="180"> <p>点击灯泡就可以打开或关闭这盏灯</p>
运行结果: