0

i have this

<div class="sc_menu">
  <a href="#" m4v="/audio/01_Tribu.m4a" oga="/audio/01_Tribu.ogg" mp3="/audio/01_Tribu.mp3"><img src="/artistes/jean-luc_gergonne/jlgergonne_thumb.jpg" alt="/artistes/jean-luc_gergonne/jlgergonne.jpg"></a>
  <a href="#" m4v="/artistes/diez/diez_demo.m4a" oga="/artistes/diez/diez_demo.ogg" mp3="/artistes/diez/diez_demo.mp3"><img src="/artistes/diez/diez_130x195.jpeg" alt="/artistes/diez/diez.jpeg"></a>
</div>

then on the same page, i have:

<div class="zen">
  <span class="player"></span>
  <span class="circle"></span>
  <span class="progress"></span>
  <span class="buffer"></span>
  <span class="drag"></span>
  <div class="button">
     <span class="icon play"></span>
     <span class="icon pause"></span>
  </div>
</div>

part of my javascript is as follows:

  this.sliderMenu = function() {

    //and loads the jPlayer with the sound files for the Artist
    $list.find('.sc_menu img').bind('click',function(){
      var $this = $(this);
      var music;
        title = $this.text();
        mp = $this.attr("mp3");
        oga = $this.attr("oga");
        m4a = $this.attr("m4a");
        m4v = $this.attr("m4v");
        ogv = $this.attr("ogv");
        webmv = $this.attr("webmv");
        poster = $this.attr("poster");
        music = {
          title: title,
          mp: mp,
          oga: oga,
        }
        console.log(music);
        self.tsunamiPlayer(music);

      //clicking on a thumb, replaces the large image
      $('<img class="st_preview"/>').load(function(){
        var $this = $(this);

        var $currImage = $('#st_main').children('img:first');
        $this.insertBefore($currImage);



  // jPlayer
  this.tsunamiPlayer = function(music) {
    ///init screen
    var player = $(".zen .player");
    var no_of_tracks = $(".sc_menu a").length;
    player.jPlayer({
      ready: function () {
        $(this).jPlayer("setMedia", {
          m4a: m4a,
          mp3: mp,
          oga: oga
        });
      },
      swfPath: "/js/jplayer/Jplayer.swf",
      supplied: "m4a, mp3, oga"         
    });

when i click on the 'a' link img, i want to load the attributes into the jPlayer instance, but i only get an undefined when i console.log(music)

what is the correct way to do this?

4

1 回答 1

0

$(this)处理程序中的变量引用元素,而您img的代码假装它是a元素,因此要修复它,请替换以下行:

$list.find('.sc_menu img').bind('click',function(){

对于这个:

$list.find('.sc_menu a').bind('click',function(e){
    e.preventDefault();
于 2012-11-22T23:15:11.513 回答