代码示例:(标识:html_script_attribute)
<!DOCTYPE html>
<html>
<body>

<h1>我的第一段 JavaScript</h1>

<p>在这里,JavaScript 更改了图像的 src 属性。</p>

<script>
function light(sw) {
  var pic;
  if (sw == 0) {
    pic = "/static/demo/images/eg_bulboff.gif"
  } else {
    pic = "/static/demo/images/eg_bulbon.gif"
  }
  document.getElementById('myImage').src = pic;
}
</script>

<img id="myImage" src="/static/demo/images/eg_bulboff.gif" width="109" height="180">

<p>
<button type="button" onclick="light(1)">开灯</button>
<button type="button" onclick="light(0)">关灯</button>
</p>

</body>
</html>
运行结果: