本文给大家分享一段基于jQuery的全选、反选和不选功能的代码,适用于网页多选后需要进行批量操作的场景(如批量删除等)。文章结合实例,代码简洁,基本覆盖选项选择操作的方方面面,希望可以帮到有需要的WEB爱好者。
//全选 全不选
$(\'#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); } });
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>
以上代码就是jquery实现全选全不选反选的全部代码,代码是不是很简单啊,希望对大家工作学习有所帮助。
本文地址:https://www.stayed.cn/item/16584
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我