Select All checkboxes using jQuery

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

I have the following html code:

    
    

15条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 07:02

    Use prop() instead -

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

    BUT I like @dmk's much more compact answer and +1'd it

提交回复
热议问题