访问动态创建的音频对象播放
问题描述:
我有一个简单的播放计数器的网页上的音频文件。它适用于初始加载音频文件,而不是在另一个jQuery的阿贾克斯也更新为同一类等(播放文件)访问动态创建的音频对象播放
jQuery(document).ready(function($) {
/*now events will only be bound to this instance*/
$('body .sermonmp3').on('playing',function(){
/* within event callbacks keep searches within the main container element*/
var fileID=$(this).attr('id');
console.log(fileID);
var data = {file_id: fileID ,security:ChurchAdminAjax.security};
jQuery.post(ChurchAdminAjax.ajaxurl, { 'action': 'ca_mp3_action','data': data },
function(response){
console.log(response);
$('body .plays').html(response);
}
);
});
})不同的文件;
我在做什么错误?
答
通过将代码放入函数并在每次创建新音频元素时调用它来解决此问题。
function bindEvents(){
$('body .sermonmp3').on('playing',function(){
var fileID=$(this).attr('id');
console.log(fileID);
var data = {file_id: fileID ,security:ChurchAdminAjax.security};
jQuery.post(ChurchAdminAjax.ajaxurl, { 'action': 'ca_mp3_action','data': data },
function(response){
console.log(response);
$('body .plays').html(response);
}
);
});
}