0

我想用我的 ajax 调用的响应来更新类播放,但只有特定的实例。

audiojs.events.ready(function() {
    var as = audiojs.createAll();

    jQuery(as).ready(function($) {
        $('.ca_podcast_file').each(function(){

            /* cache the container instance in a variable*/
            var $container=$(this);
            /* searching within the container instance for each 
            component insulates multiple instances on page*/
            var $audio= $container.find('audio');

            /*now events will only be bound to this instance*/ 
            $audio.on('playing',function(){
                /* within event callbacks keep searches within the main container element*/                     
                var fileID=$audio.attr('id');
                var data = {file_id: fileID ,security:ChurchAdminAjax.security};

                jQuery.post(ChurchAdminAjax.ajaxurl, { 'action': 'ca_mp3_action','data':   data }, 
                    function(response){

                        $($container,'.plays').html(response);
                    }
                );

            });


        });

    });
});

html标记

<div class="ca_podcast_file">
   <h3>Hearing God</h3>
       <p><audio class="sermonmp3" id="54" src="http://www.thegatewaychurch.info/wp-content/uploads/sermons/sermon2013-10-27.mp3" preload="none"/></p>
       <p><a href="http://www.thegatewaychurch.info/wp-content/uploads/sermons/sermon2013-10-27.mp3"  title="Hearing God">Hearing God</a></a> <br/>
       Mike Bollinger prophecies over some people and then helps to get going in hearing for God for ourselves <br/>
      <span style="font-size:smaller">The Gateway Church: Mike Bollinger</span> 
      Played: <div class="plays">16</div> times</p>
</div>

...重复更多的音频文件 - 一个特定的实例将是被点击的特定音频元素之一。我的代码更新得恰到好处。我的困难是线

$($container,'.plays').html(response);

我不知道如何更新该音频实例的播放次数 请问如何让它工作?

4

1 回答 1

0

原来 id 是用于音频标签的,并没有涵盖 play 类。修改 以包含 id

然后将 html 响应行更改为 $('.plays'+fileID).html(response);

于 2013-11-06T13:24:15.397 回答