HTMLOptionElement

翻译正在进行中。

HTMLOptionElement 接口表示了 <option> 元素并继承HTMLElement接口所有的类和方法。

属性

继承自其父类属性, HTMLElement.

名称 类型 描述
defaultSelected Boolean 包含了selected HTML 特性的初始值, 指示默认情况下是否选择该选项。
disabled Boolean 反映了disabled HTML 特性 的值 , 这意味着选项(option)是不可选的。如果一个选项是关闭的<optgroup>元素的子元素,那么它也可被关闭。 
form只读 HTMLFormElement

如果该选项是<select> 元素的后代,则该属性与相应HTMLSelectElement 对象的form属性具有相同的值; 否则为null

index只读 long

该选项在其所属的选项列表中的位置,以树形顺序排列。 如果该选项不是选项列表的一部分,例如为 <datalist> 元素的一部分时,该值为0

label DOMString

反映label HTML特性的值,该属性为选项提供了一个标签。 如果没有特别设置此属性,读取它返回元素的文本内容。

selected Boolean 表示当前该option是否被选择。
text DOMString 包含元素的文本内容。
value DOMString

反映value HTML特性的值(如果存在);否则反映Node.textContent 特性的值。

方法

方法继承自其父类, HTMLElement.

HTMLOptionElement.Option()是一个创建HTMLOptionElement对象的构造函数。 它有四个值:要显示的文本,文本,关联的值,,defaultSelected的值以及所选的值。 最后三个值是可选的。

格式

格式 状态 注释
HTML Living Standard
HTMLOptionElement
Living Standard No change from HTML5.
HTML5
HTMLOptionElement
Recommendation 一个构造函数Option()已经被添加。form属性可以是null值。
Document Object Model (DOM) Level 2 HTML Specification
HTMLOptionElement
Obsolete selected属性改变了它的含义:现在它指示当前是否选择该选项,如果该选项被初始选择,则不再使用该选项。defaultSelected属性不再是只读的。
Document Object Model (DOM) Level 1 Specification
HTMLOptionElement
Obsolete 初始定义

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
HTMLOptionElementChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
defaultSelectedChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
disabledChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
formChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
indexChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
labelChrome Full support YesEdge Full support 12Firefox Full support 7
Full support 7
No support ? — 7
Notes
Notes Prior to Firefox 7 the label property incorrectly returned an empty string if not defined instead of returning the element's text content.
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 7
Full support 7
No support ? — 7
Notes
Notes Prior to Firefox 7 the label property incorrectly returned an empty string if not defined instead of returning the element's text content.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
selectedChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
textChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
valueChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
See implementation notes.
See implementation notes.

参见

  • 实现此接口的HTML元素 : <option>