【发布时间】:2013-02-22 19:31:20
【问题描述】:
我有一个带有两个按钮的 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 -->
我将 jQuery 1.9.1 与 jQuerymobile 1.3 一起使用
我已经看过How to select or unselect all checkboxes in JQuery Mobile?,但它对我没有帮助。
【问题讨论】:
-
@MattBusche 在 onclick 参数中?
-
对于初学者,我强烈建议不要使用内联 JavaScript
-
你是对的,首先...
-
您应该使用
.prop更改检查状态,而不是.attr -
这似乎对我有用,这是jsBin。我认为您的代码还有其他问题。
标签: jquery jquery-mobile