--- title:

使用多选的进阶选择

下面的例子更加复杂,展示了可用在 <select> 元素上的更多功能:

<label>Please choose one or more pets:
  <select name="pets" multiple size="4">
    <optgroup label="4-legged pets">
      <option value="dog">Dog</option>
      <option value="cat">Cat</option>
      <option value="hamster" disabled>Hamster</option>
    </optgroup>
    <optgroup label="Flying pets">
      <option value="parrot">Parrot</option>
      <option value="macaw">Macaw</option>
      <option value="albatross">Albatross</option>
    </optgroup>
  </select>
</label>

你会看见:

技术概览

内容分类 Flow contentphrasing contentinteractive contentlistedlabelableresettable, and submittable form-associated element
允许的内容 Zero or more {{HTMLElement("option")}} or {{HTMLElement("optgroup")}} elements.
标签省略 {{no_tag_omission}}
允许的父元素 Any element that accepts phrasing content.
Implicit ARIA role {{ARIARole("combobox")}} with no multiple attribute and no size attribute greater than 1, otherwise {{ARIARole("listbox")}}
Permitted ARIA roles {{ARIARole("menu")}} with no multiple attribute and no size attribute greater than 1, otherwise no role permitted
DOM 接口 {{domxref("HTMLSelectElement")}}

规范

规范 状态 注释
{{SpecName('HTML WHATWG', 'forms.html#the-select-element', '<select>')}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', 'forms.html#the-select-element', '<select>')}} {{Spec2('HTML5 W3C')}}
{{SpecName('HTML4.01', 'interact/forms.html#h-17.6', '<select>')}} {{Spec2('HTML4.01')}}

浏览器兼容性

{{Compat("html.elements.select")}}

参见