源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <script> function light(sw) { var pic; if (sw == 0) { pic = "examples/pic_bulboff.gif" } else { pic = "examples/pic_bulbon.gif" } document.getElementById('myImage').src = pic; } </script> <img id="myImage" src="examples/pic_bulboff.gif" width="100" height="180"> <p> <button type="button" onclick="light(1)">Light On</button> <button type="button" onclick="light(0)">Light Off</button> </p> </body> </html>
运行结果