Jq 遍历 全选 全不选 反选

2023-02-13,,,

//全选不选
$('#checkAll').click(function () {
//判断是否被选中
var bischecked = $('#checkAll').is(':checked');
var fruit = $('input[name="check"]');
bischecked ? fruit.attr('checked', true) : fruit.attr('checked', false);
}); //反选 遍历checkbox 如果当前为选中 就设置为 不选中 反之相同
$("#tabVouchList tr").each(function () {
if ($("td:eq(0) input[name='check']", $(this)).is(':checked')) {
$(this).attr('checked', false);
} else {
$(this).attr('checked', true);
}
});
   //attr 可能会出现 第二次全选没反应的情况   prop 完美解决
$("#checkall").bind("click", function () {
$("input[type='checkbox']").prop("checked", this.checked);
});

  

HTML table

        <table id="tabVouchList">
<tr>
<th>
<input type="checkbox" name="checkAll" />
</th>
<th>
行号
</th>
<th>
名称
</th>
</tr>
<tr>
<td>
<input type="checkbox" name="check" />
</td>
<td>
行号
</td>
<td>
名称
</td>
</tr>
</table>

Jq 遍历 全选 全不选 反选的相关教程结束。

《Jq 遍历 全选 全不选 反选.doc》

下载本文的Word格式文档,以方便收藏与打印。