checkbox check all option

后端 未结 3 1666
有刺的猬
有刺的猬 2020-12-07 04:44

I have checkbox set with Category Subcategorywise...

Company
    Microsoft
    Apple

 Country
     USA
     UK

and checkbox attached to e

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 05:17

    If you can modify your HTML a little, you can come up with a general solution that will work with as many groups as you like (rather than just Country and Company).

    HTML:

    Company
    Microsoft
    Apple
    Country
    USA
    UK
    

    JavaScript:

    $(function(){
        $('.entityCheckboxHeader').click(function() {
            $('[name="'+this.name+'Sub"]').prop('checked', this.checked);
        });
    });​
    

    If you're not in a position to modify your HTML then the answer from Tats_innit is a nice, concise solution.

    There's a JSFiddle of this solution here: http://jsfiddle.net/L5qqb/

提交回复
热议问题