jQuery实现CheckBox全选、全不选

xiaoxiao2021-02-28  66

<script src="jquery-1.6.2.min.js"></script> <input type="checkbox" id="ckAll" />check all<br /> <input type="checkbox" name="sub" />1<br /> <input type="checkbox" name="sub"/>2<br /> <input type="checkbox" name="sub"/>3<br /> <input type="checkbox" name="sub"/>4<br /> <script> $("#ckAll").click(function() { $("input[name='sub']").prop("checked", this.checked); }); $("input[name='sub']").click(function() { var $subs = $("input[name='sub']"); $("#ckAll").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false); }); </script> 试过,好用,记录下。可以和datatable搭配使用。 来源:https://www.oschina.net/code/snippet_119416_5689
转载请注明原文地址: https://www.6miu.com/read-34074.html

最新回复(0)