<video id="myVideo" width="320" height="240" controls="">
<source src="/statics/demosource/movie.mp4" type="video/mp4">
<source src="/statics/demosource/movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><br>
<button onclick="setCurTime()" type="button">设置播放位置为 5 秒</button>
<p id="demo"></p>
<script>
// 获取 id="myVideo" 的 video 元素
var vid = document.getElementById("myVideo");
// 为 video 添加 "timeupdate" 事件
vid.addEventListener("timeupdate", getCurTime);
// 显示 id="demo" 的 p 元素中视频的播放位置
function getCurTime() {
document.getElementById("demo").innerHTML = "当前播放位置为 " + vid.currentTime + " 秒。";
}
// 设置播放位置为 5 秒
function setCurTime() {
vid.currentTime = 5;
}
</script>