<optgroup>

總覽

In a Web form, the HTML <optgroup> element creates a grouping of options within a <select> (en-US) element.

Content categories None.
Permitted content Zero or more <option> (en-US) elements.
Tag omission The start tag is mandatory. The end tag is optional if this element is immediately followed by another <optgroup> element, or if the parent element has no more content.
Permitted parent elements A <select> (en-US) element.
DOM interface HTMLOptGroupElement (en-US)

備註:Optgroup elements may not be nested.

屬性

This element includes the global attributes.

disabled
If this Boolean attribute is set, none of the items in this option group is selectable. Often browsers grey out such control and it won't receive any browsing events, like mouse clicks or focus-related ones.
label
The name of the group of options, which the browser can use when labeling the options in the user interface. This attribute is mandatory if this element is used.

範例

<select>
  <optgroup label="Group 1">
    <option>Option 1.1</option>
  </optgroup>
  <optgroup label="Group 2">
    <option>Option 2.1</option>
    <option>Option 2.2</option>
  </optgroup>
  <optgroup label="Group 3" disabled>
    <option>Option 3.1</option>
    <option>Option 3.2</option>
    <option>Option 3.3</option>
  </optgroup>
</select>

結果

規範

Specification
HTML Standard
# the-optgroup-element

瀏覽器相容性

BCD tables only load in the browser

參見