仍然有問題 - 如果我的代碼播放選定的音頻,按鈕將不會切換。如果我包含$(document).ready(function(){
,那麼按鈕切換但音頻不會播放!任何人都可以拯救我留下的小發型嗎?這是交付在iOS的HTML5 jQuery Mobile的項目5Javascript音頻播放/停止
感謝任何/所有幫助 Ĵ
代碼:
$(document).ready(function(){
var selSound = '18000'; //default to first sound.
var play = false; //default to paused.
function selectSound(id) {
selSound = id;
}
$('#playbtn').click(function() {
var $this = $(this);
var a = document.getElementById(selSound);
if($this.text() == 'Zap!') {
$this.children().children().text('Stop');
a.play();
} else {
$this.children().children().text('Zap!');
a.pause();
alert('Stopped playing song: '+selectedMP3);
}
});
})
HTML:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" >
<li data-swatch="b" class="ui-li ui-li-divider ui-btn ui-bar-a ui-corner-top" data-role="list-divider" role="" data-form="ui-bar-b">Select a frequency</li>
<input type="radio" name="mp3_option" id="selectSound('16000')" onclick="selectSound('16000')"><label for="selectSound('16000')">16Hz</label>
<input type="radio" name="mp3_option" id="selectSound('18000')" onclick="selectSound('18000')"><label for="selectSound('18000')">18Hz</label>
<input type="radio" name="mp3_option" id="selectSound('20000')" onclick="selectSound('20000')"><label for="selectSound('20000')">20Hz</label>
</fieldset>
<div style="text-align:center"><a href="#" data-role="button" data-inline="true" id="playbtn">Zap!</a></div></div>
你應該將'功能selectSound(ID)''的$(文件)之外。就緒(function(){});' – PeeHaa 2012-03-06 16:52:39
我會開始通過改變id屬性的值來解決你的問題。通過你的javascript的外觀,你正在選擇一個無效的id(selSound ='18000')。另見http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – 2012-03-06 17:04:17