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



我不能用jquery移动程序检查一组复选框,我有以下代码:

<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");

似乎只有最后一个复选框在工作

它们都工作得很好。你只需要触发组中所有input radiorefresh

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

jsFiddle在这里

除了:

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

对于我来说,取消选中整个无线电组:

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

这似乎不对。不需要单引号输入[type=radio]是正确的。我使用的是过时的版本(1.1.1)。如果你知道你使用的是哪个版本,那将会很有帮助。

请记住,这些都是单选按钮,一次只能选中一个。

在Jquery移动单选按钮刷新中像这样:

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

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

最新更新