html判断音视频是否播放完毕后弹出提示

使用ended事件

//音频
<audio id="audio" controls="true" autoplay="true">
  <source src="/i/song.ogg" type="audio/ogg">
  <source src="/i/song.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
audio>
<script>
    var audio = document.getElementById("audio"); 
    audio.loop = false;
    audio.addEventListener('ended', function () {  
        alert('over');
    }, false);
script> 
//视频
<video width="1024" height="576" id="shVideo">
    <source src="http://7xvgeq.com1.z0.glb.clouddn.com/H2.mp4" type="video/mp4">
video>
<script>   
    var video = document.getElementById("shVideo");
    video.addEventListener('ended', function () {  
        this.style.display = 'none';
    }, false);
script>

你可能感兴趣的:(JavaScript)