Select All checkboxes using jQuery

前端 未结 15 1582
渐次进展
渐次进展 2020-12-05 06:26

I have the following html code:

    
    

15条回答
  •  醉梦人生
    2020-12-05 06:59

    Here is a simple way to do this :

    Html :

    Selectall
    checkbox1
    checkbox2
    checkbox3

    jquery :

    $(document).ready(function(){
    $("#selectall").click(function(){
            if(this.checked){
                $('.checkboxall').each(function(){
                    $(".checkboxall").prop('checked', true);
                })
            }else{
                $('.checkboxall').each(function(){
                    $(".checkboxall").prop('checked', false);
                })
            }
        });
    });
    

提交回复
热议问题