Javascript video.currentTime事件绑定有问题
我想在视频达到5秒或更长时间后触发一个事件,但代码有问题 HTML:Javascript video.currentTime事件绑定有问题,javascript,html,events,video,Javascript,Html,Events,Video,我想在视频达到5秒或更长时间后触发一个事件,但代码有问题 HTML: <video id="video1" controls> <source src="media/video.m4v" type="video/mp4" /> <source src="media/video.webm" type="video/webm" /> <source src="media/video.ogg" type="video/ogg" />
<video id="video1" controls>
<source src="media/video.m4v" type="video/mp4" />
<source src="media/video.webm" type="video/webm" />
<source src="media/video.ogg" type="video/ogg" />
<p> Your browser does not support the HTML5 video feature. </p>
</video>
不幸的是,这不是一个有效的代码,有人知道我哪里出错了吗 您得到的是
未定义的,因为视频是jQuery对象,没有属性currentTime
,所以您可以这样得到该值
video.get(0).currentTime
或
范例
$(function () {
var video = $('#video1');
var time = 5;
function init () {
alert('Video is not available.');
}
video.on('timeupdate', function () {
if (video.get(0).currentTime >= time) {
init();
}
});
});
this.currentTime
$(function () {
var video = $('#video1');
var time = 5;
function init () {
alert('Video is not available.');
}
video.on('timeupdate', function () {
if (video.get(0).currentTime >= time) {
init();
}
});
});