use jQuery to get values of selected checkboxes

后端 未结 12 2706
旧巷少年郎
旧巷少年郎 2020-11-27 14:44

I want to loop through the checkboxgroup \'locationthemes\' and build a string with all selected values. So when checkbox 2 and 4 are selected the result would be: \"3,8\"

12条回答
  •  盖世英雄少女心
    2020-11-27 15:31

    Map the array is the quickest and cleanest.

    var array = $.map($('input[name="locationthemes"]:checked'), function(c){return c.value; })
    

    will return values as an array like:

    array => [2,3]
    

    assuming castle and barn were checked and the others were not.

提交回复
热议问题