Can't get .on( 'timeupdate', 'video' …) event to fire after inserting element dynamically

时光总嘲笑我的痴心妄想 提交于 2019-12-12 15:18:42

问题


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.

I've tried using:

 $(document).on('timeupdate', 'video', function () {
              alert("got it");            
        });

回答1:


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
}


来源:https://stackoverflow.com/questions/25088565/cant-get-on-timeupdate-video-event-to-fire-after-inserting-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!