我正在尝试传递一个独特的网址来播放不同的歌曲。如果我运行alert()
它会显示span标记的唯一href但是当我在playSound函数中尝试url = $(this).attr('href');
时它不起作用?
<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>
$(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 :(得分: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();
});
});
});
OR
$(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);
});
});
});