选中除禁用项之外的所有复选框元素(Select all checkbox elements except disabled ones)

编程入门 行业动态 更新时间:2024-10-18 05:57:38
选中除禁用项之外的所有复选框元素(Select all checkbox elements except disabled ones)

我想选择所有checkbox元素期望禁用的,

这是我的HTML

<input id="chkSelectAll" class="checkbox" type="checkbox" />Select All <div id="ContentPlaceHolder1_listItem_pnlDis_0"> <input id="checkApproved" type="checkbox" name="checkApproved" checked="checked" disabled="disabled"> </div> <div id="ContentPlaceHolder1_listItem_pnlDis_8" class="dis"> <input id="checkApproved" type="checkbox" name="ctl00$ContentPlaceHolder1$listItem$ctrl8$checkApproved"> </div>

jQuery的

$('#chkSelectAll').click(function () { var checked_status = this.checked; // alert(checked_status); $('div#item input[type=checkbox]').each(function () { this.checked = checked_status; }); })

它正在选择所有checkbox元素,但我想跳过禁用元素。

我怎样才能做到这一点?

I want to select all checkbox elements expect disabled ones,

this is my html

<input id="chkSelectAll" class="checkbox" type="checkbox" />Select All <div id="ContentPlaceHolder1_listItem_pnlDis_0"> <input id="checkApproved" type="checkbox" name="checkApproved" checked="checked" disabled="disabled"> </div> <div id="ContentPlaceHolder1_listItem_pnlDis_8" class="dis"> <input id="checkApproved" type="checkbox" name="ctl00$ContentPlaceHolder1$listItem$ctrl8$checkApproved"> </div>

jQuery

$('#chkSelectAll').click(function () { var checked_status = this.checked; // alert(checked_status); $('div#item input[type=checkbox]').each(function () { this.checked = checked_status; }); })

it's working for selecting all checkbox elements but I want to skip disabled ones.

How can I do that?

最满意答案

使用not()来排除具有禁用属性的东西。

$('#chkSelectAll').click(function () { var checked_status = this.checked; $('div#item input[type=checkbox]').not("[disabled]").each(function () { this.checked = checked_status; }); });

更简洁

$('#chkSelectAll').click(function () { var checked_status = this.checked; $('div#item input[type=checkbox]').not(":disabled").prop("checked", checked_status); });

Use not() to exclude things with a disabled attribute.

$('#chkSelectAll').click(function () { var checked_status = this.checked; $('div#item input[type=checkbox]').not("[disabled]").each(function () { this.checked = checked_status; }); });

more concise

$('#chkSelectAll').click(function () { var checked_status = this.checked; $('div#item input[type=checkbox]').not(":disabled").prop("checked", checked_status); });

更多推荐

本文发布于:2023-07-07 21:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068482.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   元素   Select   disabled   elements

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!