jquery实现全选和取消全选

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    </head>
    <body>
        <input type="checkbox" id="checkall" />全选<br />  
        <input type="checkbox" name="check" /><br />  
        <input type="checkbox" name="check"/><br />  
        <input type="checkbox" name="check"/><br />  
        <input type="checkbox" name="check"/><br />
        <script>
            $("#checkall").on('click',function() {  
                $("input[name='check']").prop("checked", this.checked);  
            });  
            $("input[name='check']").on('click',function() {  
                  var $subs = $("input[name='check']");  
                  $("#checkall").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);  
            }); 
        </script>
    </body>
</html>
原文地址:https://www.cnblogs.com/zhangjianzhen/p/9437313.html