onended 事件
当音频播放结束后执行 JavaScript:<audio onended="myFunction()">
onended 事件在视频/音频(audio/video)播放结束时触发。
- HTML 中:<element onended="myScript">
- JavaScript 中:object.onended=function(){myScript};
- JavaScript 中, 使用 addEventListener() 方法:object.addEventListener("ended", myScript);
举例:
<audio onended="if(audios[i]){this.setAttribute('src',audios[i]);i++;}else{alert('放完了');}" src="music/123.mp3" autoplay controls></audio> <script type="text/javascript"> var audios=["music/薛之谦-演员.mp3","music/MC天佑-一人我饮酒醉.mp3"],i=0; </script>
参考:http://www.runoob.com/jsref/event-onended.html