Get values from multiple selections in SELECT

后端 未结 3 860
清歌不尽
清歌不尽 2021-01-14 04:33

I have a selection box that allows you to select multiple options. I need to access all the selected values with JavaScript - possible a array of values?

3条回答
  •  情深已故
    2021-01-14 05:21

    I would use $.map:

    var values = $('#mySelect option:selected').map(function() {
        return this.value; // or $(this).val()
    }).get();
    

提交回复
热议问题