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

<p>本例演示如何将 "onplay" 事件分配给 audio 元素。</p>

<p>Press play.</p>

<audio controls onplay="myFunction()">
  <source src="/static/demo/video/horse.ogg" type="audio/ogg">
  <source src="/static/demo/video/horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction() {
  alert("The audio started to play");
}
</script>

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