get multiple values from dropdownlist in JavaScript

后端 未结 3 1952
醉酒成梦
醉酒成梦 2021-01-14 05:10

How can I get the values selected in the drop-down list, using a JavaScript function? User can select multiple values from both the elements. Following are the elements

3条回答
  •  臣服心动
    2021-01-14 06:02

    An ES6/functional style alternative to the accepted answer:

    const values = Array.apply(null, e.target.options)
      .filter(option => option.selected)
      .map(option => option.value);
    

提交回复
热议问题