Get checkbox list values with jQuery

后端 未结 8 1854
抹茶落季
抹茶落季 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:43

    You can try this...

    $(document).ready(function() {
            $("button").click(function(){
                var checkBoxValues = [];
                $.each($("input[name='check_name']:checked"), function(){
                    checkBoxValues.push($(this).val());
                });
    
                console.log(checkBoxValues);
    
            });
        });
    
    0 讨论(0)
  • 2020-12-13 18:45

    Not tested but should work:

    $("#MyDiv td input:checked").each(function()
    {
        alert($(this).attr("id"));
    });
    
    0 讨论(0)
提交回复
热议问题