选中/取消选中jquery mobile中的所有复选框都失败

idm*_*ean 1 jquery jquery-mobile

我有一个带有两个按钮的jquerymobile页面.一两个选中所有复选框,一个选中取消选中所有复选框.我第一次点击check all它有效,但在取消选中之后它不再有效.

这是我的代码:

<div data-role="page" id="selecttest">

    <div data-role="header">
        <a href="#sc" data-icon="home">SSC</a>
        <h1>...</h1>
    </div><!-- /header -->

    <div data-role="content">
        <fieldset class="ui-grid-a">
            <div class="ui-block-a"><button onclick="$('#selecttest input[type=checkbox]').attr('checked','checked').checkboxradio('refresh');" data-theme="b">check all</button></div>
            <div class="ui-block-b"><button onclick="$('#selecttest input[type=checkbox]').removeAttr('checked').checkboxradio('refresh');" data-theme="b">uncheck all</button></div>
        </fieldset>
        <fieldset data-role="controlgroup">
            <input type="checkbox" name="checkbox-v-2a" id="checkbox-v-2a">
            <label for="checkbox-v-2a">One</label>
            <input type="checkbox" name="checkbox-v-2b" id="checkbox-v-2b">
            <label for="checkbox-v-2b">Two</label>
            <input type="checkbox" name="checkbox-v-2c" id="checkbox-v-2c">
            <label for="checkbox-v-2c">Three</label>
        </fieldset>
    </div>
</div><!-- /page -->
Run Code Online (Sandbox Code Playgroud)

我正在使用jQuery 1.9.1和jQuerymobile 1.3

我已经看过如何选择或取消选择JQuery Mobile中的所有复选框?但它没有帮助我.

use*_*654 10

jQuery 1.9重新实现了对1.6中的.attr所做的更改,并在1.6.1中删除了.这意味着.attrvs .prop现在又恢复了严格.如果需要操作属性,请使用.prop,否则,使用.attr.您实际上想要使用该属性是非常罕见的.

对于复选框的选中状态,您应该使用.prop("checked",true).prop("checked",false)