一、实现功能
(1)选中头选项则子选项全部选中
(2)全部的子选项选中则头选项选中
二、部分代码
<script src=".js"></script>
<script>
$('thead input').change(function(){
var isChecked = $(this).prop('checked');//监听头选项点击事件,若当前头选项选中则checked属性变为true并赋值给isChecked
$('tbody input').prop('checked',isChecked);//将所有子选项选中属性设为true,即全部选中
})
$('tbody input').change(function(){
var allcount = $('tbody input').length;//子选项数量
var checkCount = $('tbody input:checked').length;//选中的子选项数量
var isAllChecked = allcount === checkCount;//当子选项数量和选中的子选项数量相等时,赋值true
$('thead input').prop('checked',isAllChecked);//将true带入头选项选中属性
})
</script>