javascript - 调用两次 timeupdate

标签 javascript jquery

调用两次 timeupdate 时遇到问题。 我的代码是:

$("video").on(
    "timeupdate",
    function(event){
        alert('work');
    }
);

它有效,但如果我这样做:

$('#video').html( $('#newVideo').html());

以前的代码不起作用。

我尝试下一个方法也行不通:

  1. <video id="video">

  2. `$(文档).on( "timeupdate", '视频',

    $(文档).delegate('视频',

    $("视频").bind(,

    $( "视频").live(`

最佳答案

在层次结构较高的元素上调用 .on(),以确保事件绑定(bind)适用于其下与选择器匹配的任何元素 - 无论该元素当前是否存在。

// this will work for all <video> elements within the document object
$(document).on("timeupdate", 'video', function(event){
    alert('work');
});
// if possible change 'document' to something that is
// closer up in the hierarchy to the video elements

关于javascript - 调用两次 timeupdate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19511253/

相关文章:

javascript - 异步ajax调用阻塞UI

javascript - 使用 NodeJ 读取 OSX 标签

javascript - 如何在 jQuery 中解析日期字符串并检查它是否在过去

javascript - 未捕获的类型错误 : undefined is not a function for fancy box

javascript - 如何重置 YouTube 嵌入 &lt;iframe&gt; 中的事件触摸事件监听器?

javascript - 使用 element.style 添加到以前的样式

javascript - 用户滚动经过 div 后切换图标

javascript - 如何在 jQuery 中将唯一的跨度附加到表中?

javascript - javascript有没有类似于Ruby的 `ri`的东西

jquery - 动态创建多个大小相等的固定宽度div