checkBox全选全不选

    <div>
                <label for=""><input type="checkbox" name="selectAll" class="selectAll"><span>全部</span></label>
            </div>
            <div class="optionList">
                <label for=""><input type="checkbox" class="exportChart"><span>性别结构</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>年龄比例</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>居住人口数据分布</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>国籍分布</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>民族结构</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>政治面貌分布</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>兵役状况</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>婚姻状况</span></label>
                <label for=""><input type="checkbox" class="exportChart"><span>文化程度分布</span></label>
            </div>

js

   $(".selectAll").click(function () {
                $(".exportChart:checkbox").prop("checked",this.checked)
            })
            $(".exportChart").click(function () {
                var subs = $(".exportChart");
                $(".selectAll").prop("checked",subs.length == subs.filter(":checked").length ? true :false)
            })

猜你喜欢

转载自www.cnblogs.com/yuan619821/p/9134511.html