编辑下面的代码:【加编码】
<html> <body> <p>该实例中我们向 video 元素添加 "timeupdate" 事件。currentTime属性用户获取当前视频/音频的播放位置。</p> <video id="myVideo" width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> 您的浏览器不支持 HTML5 video。 </source></source></video><br> <button onclick="setCurTime()" type="button">设置播放位置为 5 秒</button> <p id="demo"></p> <script> // 获取 id="myVideo" 的 video 元素 var x = document.getElementById("myVideo"); // 向 video 元素添加 timeupdate 事件 x.addEventListener("timeupdate", getCurTime); // 显示 id="demo" 的 p 元素中视频的当前播放位置 function getCurTime() { document.getElementById("demo").innerHTML = "当前播放位置为 " + x.currentTime + " 秒。"; } // 设置播放当前位置为 5 秒 function setCurTime() { x.currentTime = 5; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂