HTML <option> element is used to define an item contained in a <select> <optgroup> ,或 <datalist> element. As such, <option> can represent menu items in popups and other lists of items in an HTML document.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

内容类别 None.
准许内容 Text, possibly with escaped characters (like é ).
Tag omission The start tag is mandatory. The end tag is optional if this element is immediately followed by another <option> element or an <optgroup> , or if the parent element has no more content.
Permitted parents A <select> <optgroup> <datalist> 元素。
Implicit ARIA role option
Permitted ARIA roles No role permitted
DOM 接口 HTMLOptionElement

属性

此元素包括 全局属性 .

被禁用
If this Boolean attribute is set, this option is not checkable. Often browsers grey out such control and it won't receive any browsing event, like mouse clicks or focus-related ones. If this attribute is not set, the element can still be disabled if one of its ancestors is a disabled <optgroup> 元素。
label
This attribute is text for the label indicating the meaning of the option. If the label attribute isn't defined, its value is that of the element text content.
selected
If present, this Boolean attribute indicates that the option is initially selected. If the <option> element is the descendant of a <select> element whose multiple attribute is not set, only one single <option> of this <select> element may have the selected 属性。
value

The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.

范例

<select> 范例。

规范

规范 状态 注释
HTML 实时标准
The definition of '<option>' in that specification.
实时标准
HTML5
The definition of '<option>' in that specification.
推荐
HTML 4.01 Specification
The definition of '<option>' in that specification.
推荐 初始定义

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
option Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 4 Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
被禁用 Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 4 Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
label Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 注意事项
完整支持 1 注意事项
注意事项 Before 77, Firefox didn't display the value of the label attribute as option text if element's content was empty. See bug 40545 .
注意事项 Historically, Firefox has allowed keyboard and mouse events to bubble up from the <option> element to the parent <select> element, although this behavior is inconsistent across many browsers. For better Web compatibility (and for technical reasons), they will not bubble up when Firefox is in multi-process mode and the <select> element is displayed as a drop-down list. The behavior is unchanged if the <select> is presented inline and it has either the multiple attribute defined or a size attribute set to more than 1 . Rather than watching <option> elements for events, you should watch for change events on <select> 。见 bug 1090602 了解细节。
注意事项 When Mozilla introduced dedicated content threads to Firefox (through the Electrolysis, or e10s, project), support for styling <option> elements was removed temporarily. Starting in Firefox 54, you can apply foreground and background colors to <option> elements again, using the color and background-color CSS properties. See bug 910022 for more information. Note that this is still disabled in Linux due to lack of contrast (see bug 1338283 for progress on this).
IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 4 注意事项
完整支持 4 注意事项
注意事项 Before 77, Firefox didn't display the value of the label attribute as option text if element's content was empty. See bug 40545 .
Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
selected Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 4 Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes
value Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 4 Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: