<!DOCTYPE html>
<html>
<body>
<p>在本例中,我们将 "timeupdate" 事件附加到 video 元素。 currentTime 属性用于获取音频/视频播放的当前位置。</p>
<video id="myVideo" width="320" height="240" controls>
<source src="/i/photo/shanghai.mp4" type="video/mp4">
Your browser does not support the video tag.
</video><br>
<button onclick="setCurTime()" type="button">将时间位置设置为 5 秒</button>
<p id="demo"></p>
<script>
var x = document.getElementById("myVideo");
x.addEventListener("timeupdate", getCurTime);
function getCurTime() {
document.getElementById("demo").innerHTML = "The current playback position is " + x.currentTime + " seconds.";
}
function setCurTime() {
x.currentTime = 5;
}
</script>
</body>
</html>