<option>: The HTML Option element - HTML: HyperText Markup Language 编辑
The HTML <option>
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.
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.
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.
Content categories | None. |
---|---|
Permitted content | 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> , an <optgroup> or a <datalist> element. |
Implicit ARIA role | option |
Permitted ARIA roles | No role permitted |
DOM interface | HTMLOptionElement |
Attributes
This element includes the global attributes.
disabled
- 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>
element. 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 whosemultiple
attribute is not set, only one single<option>
of this<select>
element may have theselected
attribute. 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.
Examples
See <select>
for examples.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of '<option>' in that specification. | Living Standard | |
HTML5 The definition of '<option>' in that specification. | Recommendation | |
HTML 4.01 Specification The definition of '<option>' in that specification. | Recommendation | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
- Other form-related elements:
<form>
,<legend>
,<label>
,<button>
,<select>
,<datalist>
,<optgroup>
,<fieldset>
,<textarea>
,<keygen>
,<input>
,<output>
,<progress>
and<meter>
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论