如何使用JavaScript从下拉列表中获取多个选择值?

时间:2022-05-10 07:08:47

My requirement is to have select field to select multiple values for example

我的要求是选择字段来选择多个值。

<select >
  <option value="he">option 1</option>
  <option value="she" >option 2</option>
  <option value="they">option 3</option>
</select>

In this above example we can select a single value at a time but my requirement is to select multiple values.

在上面的例子中,我们可以一次选择一个值,但我的要求是选择多个值。

1 个解决方案

#1


1  

simply we can use multiple in select option :

我们可以在select选项中使用多个选项:

<select multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

Refer:https://www.w3schools.com/tags/att_select_multiple.asp

参见:https://www.w3schools.com/tags/att_select_multiple.asp

#1


1  

simply we can use multiple in select option :

我们可以在select选项中使用多个选项:

<select multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

Refer:https://www.w3schools.com/tags/att_select_multiple.asp

参见:https://www.w3schools.com/tags/att_select_multiple.asp