var $ckAll = $("input[name=' ckAll']"); var $ckItm = $("input[name='ckItm']"); var len = $ckItm.length; $ckAll.click(function() { // Get the current selected status of $ckAll. If selected, other sub-checkboxes will be selected, otherwise they will be cancelled. $ckItm.prop('checked',this.checked); }); $ckItm.click(function() { // Bind the judgment event to b var b=$ckItm.filter(":checked").length==len;// When the selected The number of sub-checkboxes is equal to the total number, and the main checkbox will be selected // Determine through ternary operation var flag=$ckAll.prop("checked",b?true:false) ; });
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn