动态插入元素后无法获取.on('timeupdate','video'....)事件 [英] Can't get .on( 'timeupdate', 'video' ....) event to fire after inserting element dynamically
问题描述
我正在使用自定义控件向页面动态添加视频元素。除了用于更新搜索栏位置的'timeupdate'事件外,我的所有自定义控件都正常工作。
I am dynamically adding a video element to the page with custom controls. All of my custom controls are working except for the 'timeupdate' event which I'm using to updated the seek bar position.
我尝试过使用:
$(document).on('timeupdate', 'video', function () {
alert("got it");
});
推荐答案
我试图通过委派事件来解决这个问题。 api.jquery.com/on
从文件委托我可以解雇其他活动,但不是视频元素本身。所以我从那时起就睡了,事实证明事件绑定没有抓住,因为它们是在对象存在之前声明的。通过在创建视频元素后添加事件绑定来解决此问题。
I attempted to solve this with delegated events. api.jquery.com/on I could fire other events fine when delegating from the document, but not on the video element itself. So I slept since then and it turns out the event bindings weren't taking hold because they were getting declared before the object existed. Solved it by adding the event bindings after the video element is created.
function(){
//add video element
...
//add bindings
}
这篇关于动态插入元素后无法获取.on('timeupdate','video'....)事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!