现场演示(我能理解反正!):
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