How to get the values of all checked checkboxes using jQuery

前端 未结 6 1923
傲寒
傲寒 2020-12-15 11:45

I don\'t know how to pass the selected values of the checkboxes. Any help or suggestions will be a big help for me.

As of now here is my code I am stuck in passing th

6条回答
  •  清歌不尽
    2020-12-15 12:18

    You can use something like this before your ajax call:

    var ids=[]; 
    $('input[type=checkbox]:checked').each(function(){
        ids.push($(this).val());
    });
    

    But it is strongly recommended to wrap your checkboxes in some div, and represent it in your jquery selector. Because in current way you can select and send to server some other checkboxes on your page.

提交回复
热议问题