<option>: The HTML Option element

<option> HTML 元素用于定义 <select><optgroup><datalist> 元素中包含的项目。因此,<option> 可以表示弹出窗口中的菜单项以及 HTML 文档中的其他项目列表。

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

Try it

属性

¥Attributes

该元素包括 全局属性

¥This element includes the global attributes.

disabled

如果设置了此布尔属性,则此选项不可选中。通常,浏览器会将此类控件显示为灰色,并且它不会接收任何浏览事件,例如鼠标单击或与焦点相关的事件。如果未设置此属性,且该元素的祖级之一是已禁用的 <optgroup> 元素,则该元素仍可被禁用。

label

该属性是指示选项含义的标签文本。如果未定义 label 属性,则其值为元素文本内容的值。

selected

如果存在,此布尔属性表示最初选择了该选项。如果 <option> 元素是未设置 multiple 属性的 <select> 元素的后代,则该 <select> 元素中只有一个 <option> 可以具有 selected 属性。

value

如果选择此选项,此属性的内容表示要随表单提交的值。如果省略此属性,则从选项元素的文本内容中获取值。

使用 CSS 设计样式

¥Styling with CSS

<option> 元素的样式受到很大限制。选项不会继承父级上设置的字体。在 Firefox 中,只能设置 colorbackground-color,但在 Chrome 和 Safari 中无法设置任何属性。你可以在 我们的高级表单样式指南 中找到有关样式的更多详细信息。

¥Styling the <option> element is highly limited. Options don't inherit the font set on the parent. In Firefox, only color and background-color can be set, however in Chrome and Safari it's not possible to set any properties. You can find more details about styling in our guide to advanced form styling.

示例

¥Examples

示例请参见 <select>

¥See <select> for examples.

技术总结

¥Technical summary

内容类别 没有任何。
允许的内容 文本,可能带有转义字符(如 &eacute;)。
标签遗漏 开始标记是强制性的。如果此元素后面紧跟着另一个 <option> 元素或 <optgroup>,或者父元素没有更多内容,则结束标记是可选的。
允许的父级 <select><optgroup><datalist> 元素。
隐式 ARIA 角色 option
允许的 ARIA 角色 不允许 role
DOM 接口 HTMLOptionElement

规范

Specification
HTML Standard
# the-option-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also