从javascript生成的li元素触发onclick

时间:2013-11-30 21:46:20

标签: javascript jquery onclick jplayer

在我的网站www.danielLmusic.com上,在听力部分,我试图在点击j-player播放列表中的项目时激活唱机手臂动画gif(recordstart.gif)。难点在于播放列表元素是通过javascript加载的,并且对.jp-playlist li a的正常引用不起作用。我查看了这个网站,发现有人建议使用on('click','a',function(){功能,这让我75%,除了它只加载用户点击一首歌的第二时间的gif而不是首先。我粘贴下面的html和javascript ...任何帮助将不胜感激!谢谢

<div class="jp-playlist">
                              <ul>
                                <li></li> <!-- Empty <li> so your HTML conforms with the W3C spec -->
                              </ul>
                            </div>

<script type="text/javascript">
    $(window).load(function(){
        $('.jp-playlist ul').on('click','a',function(){
       $('.jp-playlist a').click(function(){
          $('#soundsystem').css('background-image','url(graphics/recordstart.gif)');

           setTimeout(function (){ 
               $('#soundsystem').css('background-image','url(graphics/recordplaying.gif)');
           },1500);


       });
       $('a.jp-pause').click(function(){
           $('#soundsystem').css('background-image','url(graphics/recordstop.gif)');
       });
       $('a.jp-stop').click(function(){
          $('#soundsystem').css('background-image','url(graphics/recordstop.gif)');
       });
   });
});
    </script>

1 个答案:

答案 0 :(得分:-1)

try this:
<script type="text/javascript">
    $(window).load(function(){
        $('body').on('click','.jp-playlist ul a',function(){
       $('.jp-playlist a').click(function(){
          $('#soundsystem').css('background-image','url(graphics/recordstart.gif)');

           setTimeout(function (){ 
               $('#soundsystem').css('background-image','url(graphics/recordplaying.gif)');
           },1500);


       });
       $('a.jp-pause').click(function(){
           $('#soundsystem').css('background-image','url(graphics/recordstop.gif)');
       });
       $('a.jp-stop').click(function(){
          $('#soundsystem').css('background-image','url(graphics/recordstop.gif)');
       });
   });
});
    </script>