<!-- 全选框--> <input type="checkbox" class="box-title" onclick="selectAll()"><!-- 需要被选中的部分--> <input name='box' type='checkbox'> <input name='box' type='checkbox'> <input name='box' type='checkbox'> <input name='box' type='checkbox'>
var isCheckAll = false; function selectAll() { // 取消全选 if (isCheckAll) { $("input[name='box']").each(function() { this.checked = false; this.parentNode.parentNode.style.backgroundColor=""; }); isCheckAll = false; } // 全选 else { $("input[name='box']").each(function() { this.checked = true; this.parentNode.parentNode.style.backgroundColor="#F78181"; }); isCheckAll = true; } }