改变灯泡的源

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <img id="myImage" onclick="changeImage()" src="/i/eg_bulboff.gif" />
  6.  
  7. <p>单击灯泡打开/关闭灯。</p>
  8.  
  9. <script>
  10. function changeImage() {
  11. var image = document.getElementById('myImage');
  12. if (image.src.match("bulbon")) {
  13. image.src = "/i/eg_bulboff.gif";
  14. } else {
  15. image.src = "/i/eg_bulbon.gif";
  16. }
  17. }
  18. </script>
  19.  
  20. </body>
  21. </html>