2013-01-18 71 views
9

我無法檢查一組複選框編程與jQuery Mobile的,我有以下代碼:選中和取消選中單選按鈕

<div data-role="fieldcontain" id="div_radio" class="radiogroup"> 
    <fieldset data-role="controlgroup"> 
     <input type="radio" name="radio-pieces" id="radio-choice-1" value="3" checked="checked" /> 
     <label for="radio-choice-1">1 to 3</label> 

     <input type="radio" name="radio-pieces" id="radio-choice-2" value="5" /> 
     <label for="radio-choice-2">4 to 5</label> 

     <input type="radio" name="radio-pieces" id="radio-choice-3" value="6" /> 
     <label for="radio-choice-3">over 5</label> 
    </fieldset> 
</div> 

如果我做的:$("input[type='radio']:last").attr("checked",true).checkboxradio("refresh");一切都運行完美,但沒有這項工作在所有:

$("input[type='radio']:first").attr("checked",true).checkboxradio("refresh"); 
$("input[type='radio']:eq(0)").attr("checked",true).checkboxradio("refresh"); 
$("input[type='radio']:eq(1)").attr("checked",true).checkboxradio("refresh"); 
$("input[type='radio']:eq(2)").attr("checked",true).checkboxradio("refresh"); 

我該如何正確操縱這些元素?取消選中所有複選框也可以正常工作:

$("input[type='radio']").attr("checked",false).checkboxradio("refresh"); 

看起來,唯一的複選框工作是最後一個。

+0

任何幫助嗎?請 –

回答

22

他們都工作得很好。您只需在組中的所有input radio上觸發refresh

$("input[type='radio']:first").attr("checked", "checked"); 
$("input[type='radio']").checkboxradio("refresh"); 

jsFiddle是here

+0

就是這樣!我不得不刷新組中的所有輸入收音機!非常感謝!!! –

0

這看起來不對。 單引號不需要輸入[type = radio]是正確的。 我正在使用過時的版本(1.1.1)。 這將有助於瞭解您正在使用的版本。

請記住,這些是單選按鈕,一次只能選擇一個。

0

在jQuery Mobile的單選按鈕刷新這樣的:

$(".iscfieldset input[type='radio']:first").attr("checked", "checked"); 


    $(".iscfieldset input[type='radio']").checkboxradio().checkboxradio("refresh"); 

嘗試對我來說

4

沒有這方面的工作工作得很好,我只是:

$('#reset').click(function(){ 
    $('#Store').trigger("click").trigger("click"); // yes... twice 
}); 

在jQuery Mobile的1.4.2。

1

對我的作品這取消整個集團的收音機:

$(".my_class").removeAttr("checked"); 
$(".my_class").checkboxradio("refresh");