現場演示(我能理解反正!):
JS
var selectedMP3;
$('input[name=mp3_option]').change(function() {
selectedMP3 = $('input[name=mp3_option]:checked').val();
});
$('#controlButton').click(function() {
var $this = $(this);
if($this.text() == 'Play') {
$this.children().children().text('Pause');
} else {
$this.children().children().text('Play');
alert('Stopped playing song: '+selectedMP3);
$('input[name=mp3_option]').attr('checked',false).checkboxradio('refresh');
}
});
HTML
<div data-role="page" id="home">
<div data-role="content">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose a song:</legend>
<input type="radio" name="mp3_option" id="radio-choice-1" value="song-1.mp3" />
<label for="radio-choice-1">MP3 1</label>
<input type="radio" name="mp3_option" id="radio-choice-2" value="song-2.mp3" />
<label for="radio-choice-2">MP3 2</label>
<input type="radio" name="mp3_option" id="radio-choice-3" value="song-3.mp3" />
<label for="radio-choice-3">MP3 3</label>
<input type="radio" name="mp3_option" id="radio-choice-4" value="song-4.mp3" />
<label for="radio-choice-4">MP3 4</label>
</fieldset>
</div>
<a href="#" data-role="button" data-inline="true" id="controlButton">Play</a>
</div>
</div>
菲爾嗨 - 感謝這麼多花時間在這個問題上的工作 - 它是絕對現貨上。我現在可以看到你是如何做到這一點,併爲下一次學習:)非常感謝-Jim – Jimbly2 2012-02-07 10:04:30
輕微snagette - 我不能讓它播放MP3 - 只是不斷返回'undefined'或'8000.mp3'(第一個音頻文件選擇)它也會爲其他選項返回相同的8000.mp3 - 我已經檢查過並且文件絕對在正確的位置..任何線索?感謝Jim – Jimbly2 2012-02-07 21:20:29
鏈接到演示或http://jsfiddle.net? – 2012-02-07 21:31:23