1
我正在使用jQuery UI對話框和jQuery來選擇一個「收音機」按鈕。jQuery選擇器錯誤
我有2個對話框,一個用於「計算器」,另一個用於「expert_mode」。
但是,當我在計算器下選擇一個'input[value="simple"]'
時,它也影響具有相同名稱的expert_mode下的input
,如何解決?
以下是我的代碼:
這是我的HTML(簡體):
<div name="widget">
<div name="calculator">
<input name="mode" value="a" type="radio" **checked="checked"**/>
<input name="mode" value="b" type="radio"/>
<input name="mode" value="c" type="radio"/>
</div>
<div name="expert">
<input name="mode" value="simple" type="radio"/>
<input name="mode" value="advanced" type="radio"/>
<input name="mode" value="custom" type="radio"/>
</div>
</div>
和JavaScript:
var widget=$('div[name="widget"]');
var calculator=widget.find('div[name="calculator"]');
var expert=widget.find('div[name="expert"]');
calculator.dialog();
expert.dialog();
然後,當我這樣做:
expert.find('input[value="simple"]').attr('checked',true);
它變成:
<div name="widget">
<div name="calculator">
<input name="mode" value="a" type="radio"/> ***Here, "checked" disappear!!***
<input name="mode" value="b" type="radio"/>
<input name="mode" value="c" type="radio"/>
</div>
<div name="expert">
<input name="mode" value="simple" type="radio" checked="checked"/>
<input name="mode" value="advanced" type="radio"/>
<input name="mode" value="custom" type="radio"/>
</div>
</div>
您是對的。
我忘了一次只能檢查一個共享同一個名字的電臺。
謝謝!
(所以,這根本就不是關於jquery的問題......) – user1034937