bootstrap中checkbox全选,反选
程序员文章站
2022-06-08 13:55:01
...
<span style="white-space:pre"> </span>$("#selectAll").click(function () {
$("#owners input:checkbox").each(function () {
$(this).prop('checked', true);//
});
});
$("#unSelect").click(function () {
$("#owners input:checkbox").removeAttr("checked");
});
$("#reverse").click(function () {
$("#owners input:checkbox").each(function () {
this.checked = !this.checked;
});
});
<input type="button" value="全选" class="btn" id="selectAll">
<input type="button" value="全不选" class="btn" id="unSelect">
<input type="button" value="反选" class="btn" id="reverse">
注:
.attr('checked): //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false
.prop('checked'): //16+:true/false