<optgroup>

HTML元素 <optgroup> <select> 元素中的选项创建分组。

内容分类
允许的内容 0或多个 <option> 元素
标签省略 开始标签是必须的。当该元素后面也跟着一个 <optgroup> 元素,或该元素的父元素没有其他内容时,结束标签可省略。
允许的父元素 一个 <select> 元素.
Implicit ARIA role group
Permitted ARIA roles No role permitted
DOM 接口 HTMLOptGroupElement
Note: Optgroup elements may not be nested.

属性

这个元素包含 global attributes

disabled
如果设置了这个布尔值,则不能选择这个选项组中的任何选项。通常浏览器会置灰这样的控件,它不接受任何浏览器事件,如鼠标点击或者焦点相关的事件。
label
选项组的名字,浏览器用以在用户界面中标记选项。使用这个元素时必须加上这个属性。

示例

<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>

结果

规范

规范 状态 注释
HTML Living Standard
<optgroup>
Living Standard
HTML5
<optgroup>
Recommendation
HTML 4.01 Specification
<optgroup>
Recommendation

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
optgroupChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
disabledChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 8Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
labelChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

另请参阅