var $ckAll = $("input[name='ckAll']");var $ckItm = $("input[name='ckItm']");var len = $ckItm.length;$ckAll.click(function() { //Gets the current selected state of $ckAll. If selected, the other subcheck boxes are selected, or otherwise canceled $ckItm.prop('checked',this.checked);});$ckItm.click(function() { //Bind b to judge events var b=$ckItm.filter(":checked").length==len;//When the number of selected subcheckboxes equals the total number, the primary checkbox is selected //It is judged by ternary operation var flag=$ckAll.prop("checked",b?true:false);});