<!DOCTYPE html> <html> <body> <script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bul1")) //这里的意思是让bul1与图片名称匹配,如果图片名称中含有bul1,则为真 { element.src="/images/pic_bulboff.gif"; } else { element.src="/images/pic_bul1.gif"; } } </script> <img id="myimage" onclick="changeImage()" src="/images/pic_bulboff.gif" width="100" height="180"> <p>点击灯泡就可以打开或关闭这盏灯</p> </body> </html>