2013-10-22 53 views
1

有问题要调用两次timeupdate。 我的代码是:调用两次timeupdate

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

它的工作,但如果我这样做:

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

前面的代码不工作。

我试下顺便也不起作用:

  1. <video id="video">

  2. `$(文件)。在( “timeupdate”, '视频',

    的$(document)。委托( '视频',

    $( “视频”)。绑定(,

    $( “视频”).L元素越往上层次结构上IVE(`

回答

0

我的解决办法是:

function initPlayer() { 
    var player = $(document).find('video')[0]; 
    if (player) { 
     player.addEventListener('timeupdate', function() { 
      alert('work'); 
     }, false) 
    } 
} 

必须更改后和前调用函数之前再次.find视频标签。通过这种方式:

$("#button").click(function() { 
    $('#video').html($('#newVideo').html()); 
    initPlayer(); 
}); 
1

呼叫.on(),以确保任何元素在它之下的情况下结合的作品选择匹配 - 该元素是否当前存在与否。

// 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 
+0

这不适用于timeupdate。我也尝试:'$(document).on(“timeupdate”,'video', $(document).delegate('video', $(“video”)。bind( $(“video”)。生活(' –