<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Light</title>
</head>
<script>
function aaaa() {
element = document.getElementById('myimage');
if (element.src.match('bulbon')){
element.src = '../image/pic_bulboff.gif'
}else {
element.src = '../image/pic_bulbon.gif'
}
}
</script>
<body>
<img src="../image/pic_bulboff.gif" width="100" height="180" id="myimage" onclick="aaaa()">
<p>点击灯泡就可以打开或关闭这盏灯</p>
</body>
</html>
注意路径是相对于本代码目录的相对路径