使用Jquery Mobile检查和取消选中单选按钮

dan*_*sgb 9 html javascript radio-button jquery-mobile cordova

我无法使用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>
Run Code Online (Sandbox Code Playgroud)

如果我这样做:$("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");
Run Code Online (Sandbox Code Playgroud)

我该如何正确操纵这些元素?取消选中所有复选框也可以正常工作:

$("input[type='radio']").attr("checked",false).checkboxradio("refresh");
Run Code Online (Sandbox Code Playgroud)

似乎唯一的复选框是最后一个.

pet*_*erm 22

他们都工作得很好.你只需要触发refresh所有input radio组.

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

jsFiddle就在这里.


use*_*388 5

除了:

$('#reset').click(function(){
    $('#Store').trigger("click").trigger("click"); // yes... twice
});
Run Code Online (Sandbox Code Playgroud)

在jQuery Mobile 1.4.2上。