說我有這樣一組的三個單選按鈕:如何以編程方式刷新jQuery Mobile中的一組單選按鈕?
<label for="a-1">A</label>
<input type="radio" name="a" id="a-1" value="1" />
<label for="a-2">A</label>
<input type="radio" name="a" id="a-2" value="2" />
<label for="a-3">A</label>
<input type="radio" name="a" id="a-3" value="3" />
與第一無線電設定爲checked="true"
ALA
$("input").eq(0).attr("checked", true);
的JQM API for checkboxradio說以下內容:
$(".selector").prop("checked", true).checkboxradio("refresh");
以編程方式設置單選按鈕。
問題:
如果我需要收音機從一個按鈕,切換到另一個?所以....
$("input").eq(1).trigger("click");
是否總是需要單獨更新我的點擊處理我的單選按鈕或不應該這項工作開箱?畢竟,當我有一個非JQM單選按鈕組並觸發單選單元時,先前選中的按鈕將自動取消選中。
謝謝!
編輯:
平原例如:
var foo = '<input type="radio" checked="checked" name="a" id="a-1" value="1" />' +
'<input type="radio" name="a" id="a-2" value="2" />' +
'<input type="radio" name="a" id="a-3" value="3" />';
$("div.ui-content").append($(foo));
$(document.getElementById("a-2")).trigger("click");
這產生三個單選按鈕,第一個被選擇。在點擊時,第二臺收音機正在被選中,並且第一臺收音機未被選中。
EDIT:
JQM實施例:
$("div.ui-content").empty()
var bar = '<div data-role="controlgroup">' +
'<input type="radio" name="a" id="a-1" value="choice-1" checked="checked">' +
'<label for="a-1">1</label>' +
'<input type="radio" name="a" id="a-2" value="choice-2">' +
'<label for="a-2">2</label>' +
'<input type="radio" name="a" id="a-3" value="choice-3">' +
'<label for="a-3">3</label>' +
'</div>';
$("div.ui-content").append($(bar)).enhanceWithin();
$("input").eq(2).trigger("click").checkboxradio("refresh");
這將導致在2個選擇單選按鈕。
究竟你想做?動態選擇一個單選按鈕而無需刷新收音機組,對嗎? – TheMohanAhuja
不選擇,但觸發點擊。在普通的HTML中,C上的'trigger(「click」)'取消了收音機A的選擇,而JQM則沒有。見http://jsbin.com/ofuhaw/1202 – frequent