Get checkbox list values with jQuery

后端 未结 8 1860
抹茶落季
抹茶落季 2020-12-13 18:35

In a div, I have some checkbox. I\'d like when I push a button get all the name of all check box checked. Could you tell me how to do this ?

8条回答
  •  温柔的废话
    2020-12-13 18:39

    $(document).ready(function() {
        $('#someButton').click(function() {
            var names = [];
            $('#MyDiv input:checked').each(function() {
                names.push(this.name);
            });
            // now names contains all of the names of checked checkboxes
            // do something with it
        });
    });
    

提交回复
热议问题