
currentTime 属性会以秒为单位返回当前媒体元素的播放时间。设置这个属性会改变媒体元素当前播放位置。
在线示例
将时间位置设置为 5 秒:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML 音频/视频 currentTime 属性使用-大卫编程网(div.cn)</title>
</head>
<body>
<button onclick="getCurTime()" type="button">获得当前时间的位置</button>
<button onclick="setCurTime()" type="button">将时间位置设置为 5 秒</button>
<br>
<video id="video1" controls="controls">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
您的浏览器不支持 HTML5 video 标签。
</video>
<script>
myVid=document.getElementById("video1");
function getCurTime()
{
alert(myVid.currentTime);
}
function setCurTime()
{
myVid.currentTime=5;
}
</script>
</body>
</html>测试看看 ‹/›定义和用法
currentTime属性设置或返回音频/视频播放的当前位置(以秒为单位)。
设置此属性时,播放将跳至指定位置。
浏览器兼容性
IEFirefoxOperaChromeSafari
所有主流浏览器都支持 currentTime 属性。
注意:Internet Explorer 8 及之前的版本不支持该属性。
语法
设置 currentTime 属性:
audio|video.currentTime="seconds"
返回 currentTime 属性:
audio|video.currentTime
属性值
| 值 | 描述 |
|---|---|
| seconds | 指示音频/视频播放的当前位置,以秒计。 |
技术细节
| 返回值: | 数字值,表示秒 |
|---|