how to get multiple checkbox value using jquery

前端 未结 12 769
终归单人心
终归单人心 2020-11-29 20:11

How can I get the value of checkboxes which are selected using jquery? My html code is as follows:



        
12条回答
  •  悲哀的现实
    2020-11-29 20:17

    To get an array of values from multiple checked checkboxes, use jQuery map/get functions:

    $('input[type=checkbox]:checked').map(function(_, el) {
        return $(el).val();
    }).get();
    

    This will return array with checked values, like this one: ['1', '2']

    Here is working example on jsfiddle: http://jsfiddle.net/7PV2e/

提交回复
热议问题