0
我想通過一個獨特的URL來播放不同的歌曲。如果我運行alert()
它顯示span標記的唯一href,但是當我在playSound函數中嘗試url = $(this).attr('href');
時,它不起作用?jQuery將href傳遞給soundManager
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();
});
});
});
謝謝,這有點作品,但我點擊一個按鈕後,所有3個按鈕將播放相同的聲音(第一個按鈕點擊聲音) – user3525661