选中/取消选中jQuery Mobile中的所有复选框失败 [英] Check/Uncheck all checkboxes in jquery mobile fails
问题描述
我有一个带有两个按钮的jquerymobile页面.一两选中所有复选框,一取消选中所有复选框. 我第一次单击check all
,它会起作用,但是取消选中后,它将不再起作用.
I have a jquerymobile page with two buttons. One two check all checkboxes and one to uncheck all checkboxes. First time I click on check all
it works, but after unchecking it doesn't works anymore.
这是我的代码:
<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一起使用
I'm using jQuery 1.9.1 with jQuerymobile 1.3
我已经看过如何在JQuery Mobile中选择或取消选择所有复选框?但这对我没有帮助.
I've already taken a look at How to select or unselect all checkboxes in JQuery Mobile? but it hasn't helped me.
推荐答案
jQuery 1.9重新恢复了在1.6中对.attr所做的更改并在1.6.1中删除了这些更改.这意味着.attr
与.prop
现在又回到了严格的状态.如果需要操纵属性,请使用.prop
,否则,请使用.attr
.实际上很少要使用该属性.
jQuery 1.9 re-instated the changes that were done to .attr in 1.6 and removed in 1.6.1. This means that the .attr
vs .prop
is now back to being strict. If you need to manipulate properties, use .prop
, else, use .attr
. It's very rare that you actually would want to work with the attribute.
对于复选框的选中状态,您应该使用.prop("checked",true)
或.prop("checked",false)
For checked state of a checkbox, you should be using .prop("checked",true)
or .prop("checked",false)
这篇关于选中/取消选中jQuery Mobile中的所有复选框失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!