2

我正在尝试在 HTML5 视频达到特定的第二个值时执行基本功能。目前我没有任何运气,并希望我能在这里得到一些帮助。这是我到目前为止使用的代码:

jQuery(function(){
    jQuery("video").bind("timeupdate", function() {
        if(this.currentTime == "6") { alert("six seconds in"); }
        // also tried the above line with the 6 not in quotes
    });
});

我只想围绕视频做一个非常基本的内容交换,但到目前为止还没有多少运气。提前感谢您的帮助!

4

2 回答 2

1

这个 vanilla JavaScript 对我来说很好用:

video.addEventListener('timeupdate', function(e) {
    如果 (e.target.currentTime == 6) ...
}, 错误的);
于 2010-09-10T03:24:25.327 回答
1

currentTime是浮点值,而不是整数。删除小数部分进行比较。

var currentTime = parseInt(this.currentTime, 10);
if(currentTime == 6) { 
    ..
}
于 2010-09-10T03:29:42.990 回答