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)
            })

 

posted @ 2018-06-04 17:31  微语123  阅读(93)  评论(0编辑  收藏  举报