2014-04-12 2 views
0

다른 노래를 재생할 고유 URL을 전달하려고합니다. alert()을 실행하면 span 태그의 고유 href가 표시되지만 playSound 함수에서 url = $(this).attr('href');을 시도해도 작동하지 않습니다.href를 soundManager에 전달하는 jQuery

HTML 페이지

<head> 
<link type="text/css" href="css/smoothness/jquery-ui-1.8.16.custom.css" rel="stylesheet" /> 
<link type="text/css" href="css/mp3player.css" rel="stylesheet" /> 
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> 
<script type="text/javascript" src="js/jquery-ui-1.8.9.custom.min.js"></script> 
<script type="text/javascript" src="js/jscroller.js"></script> 
<script src="js/soundmanager2-jsmin.js"></script> 
<script type="text/javascript" src="js/mp3player.js"></script> 

<head> 

<body> 
<div id="wrapper"> 
<div id="player"> 
<img src="images/background.png"/> 
<img src="images/play_button.png" id="play_btn"/> 
<img src="images/pause_button.png" id="pause_btn"/> 
<img src="images/stop_button.png" id="stop_btn"/> 
<img src="images/fwd_button.png" id="fwd_btn"/> 
<img src="images/back_button.png" id="back_btn"/> 
<img src="images/vb10.png" id="volumebar"/> 
<div id="progressbar"></div> 
<div id="time"></div> 
<div id="scroller_container"> 
<div id="scroller"> 
    <p></p> 
</div> 
</div> 
</div> 
</div> 

<table style="width: 100%"> 
    <tr> 
     <td> 
     <span class="Play" href="../sounds/5.mp3"><img src="images/play_button.png"/></span> 

     <span class="Play" href="../sounds/4.mp3"><img src="images/play_button.png"/></span> 

     <span class="Play" href="../sounds/3.mp3"><img src="images/play_button.png"/></span> 


     </td> 
    </tr> 
</table> 

</body> 

MP3Player.js #

$(document).ready(function() { 
    soundManager.url = 'swf'; 
    soundManager.flashVersion = 8; 
    var theMP3; 
    var currentSong =0; 
     soundManager.onready(function() { 
      function playSound(){ 
       theMP3= soundManager.createSound({ 
        id:'sound'+currentSong, 
        url: href 
            }); 
      theMP3.play(); 
      }; 

     $(".Play").click(function(){     
       var href = $(this).attr('href');     
       playSound(); 

      });   
    }); 
}); 

답변

0

, 그것을 이런 식으로

$(document).ready(function() { 
    var urll='' 
    soundManager.url = 'swf'; 
    soundManager.flashVersion = 8; 
    var theMP3; 
    var currentSong =0; 
     soundManager.onready(function() { 
      function playSound(){ 
       theMP3= soundManager.createSound({ 
        id:'sound'+currentSong, 
        url: urll 
            }); 
      theMP3.play(); 
      }; 

     $(".Play").click(function(){     
       urll = $(this).attr('href');     
       playSound(); 

      });   
    }); 
}); 

또는

$(document).ready(function() { 
    var urll = '' 
    soundManager.url = 'swf'; 
    soundManager.flashVersion = 8; 
    var theMP3; 
    var currentSong = 0; 
    soundManager.onready(function() { 
     function playSound(str) { 
      theMP3 = soundManager.createSound({ 
       id: 'sound' + currentSong, 
       url: str 
      }); 
      theMP3.play(); 
     }; 

     $(".Play").click(function() { 
      urll = $(this).attr('href'); 
      playSound(urll); 

     }); 
    }); 
}); 
+0

감사하십시오 좀 작동하지만 버튼을 클릭하면 3 개의 버튼이 모두 동일한 사운드를 재생합니다 (첫 번째 버튼 클릭 사운드) – user3525661

관련 문제