拨打两次timeupdate

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

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

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

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

以前的代码不工作。

我尝试下一步也不行:

  1. `$(document).on(“timeupdate”,’video’,

    (文档)$ .delegate( ‘video’,

    $( “video”)。绑定(,

    $(“video”).live(`

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

 // this will work for all  

我的解决方案是:

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

必须。在更改之后和之前的呼叫function之前再次查找video标签。 通过这种方式:

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