HTMLOptionElement

option 要素 (HTML)

[1] HTML の option 要素は、 メニュー制御子 (select) の選択肢を表します。

[2] 仕様書:

[3]

開始タグ
必須
終了タグ (HTML 4)
省略可能
終了タグ (XHTML 1)
必須
出現できる文脈
select 要素や optgroup の子供として任意個
内容模型
#PCDATA
属性
属性名属性値既定値説明出典
class(なし)級[HTML 4] %coreattrs ⊂ %attrs, [XHTML 1] Core ⊂ Common
dir書字方向[HTML 4] %i18n ⊂ %attrs, [XHTML 1] I18N ⊂ Common
disabled(真偽値属性)(偽)無効[HTML 4]
idID(なし)一意識別子[HTML 4] %coreattrs ⊂ %attrs, [XHTML 1] Core ⊂ Common
label%Text(内容)階層名[HTML 4]
lang自然言語[HTML 4] %i18n ⊂ %attrs
xml:lang自然言語[XHTML 1] I18N ⊂ Common
onclick%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
ondblclick%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onkeydown%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onkeypress%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onkeyup%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onmousedown%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onmousemove%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onmouseout%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onmouseover%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
onmouseup%Script(なし)[HTML 4] %events ⊂ %attrs, [XHTML 1] Events ⊂ Common
selected(真偽値属性)(偽)初期選択[HTML 4]
styleスタイル情報[HTML 4] %coreattrs ⊂ %attrs, [XHTML 1] Style ⊂ Common
title注釈的題[HTML 4] %coreattrs ⊂ %attrs, [XHTML 1] Core ⊂ Common
value(内容)値[HTML 4]

フォーム

[4] 誤り処理

フォーム制御子としての値は、 明示的に指定されない場合 (内容が用いられる場合) は、 textContent DOM属性の値により初期化しなければなりません。 WF2 2.18

レンダリング

[5] 誤り処理

テキスト節点以外が含まれる場合、 どうレンダリングされるべきかは未定義です。 実用上、2つの可能性があります:

WF2 2.18

[6] select 外

select 要素外の option は、 span と同じようにレンダリングするべきです。 WF2 2.18

HTMLOptionElement インターフェイス

界面名
HTMLOptionElement DOM1 HTML, DOM2 HTML, HTML5
旧 JavaScript 名
Option JavaScript 1.0
親界面
HTMLElement
要素
option
defaultSelectedOption (JavaScript 1.1), HTML5
disabledHTML5
formHTML5
indexHTML5
labelHTML5
lengthOpera
selectedOption (JavaScript 1.0), HTML5
textOption (JavaScript 1.0), HTML5
valueOption (JavaScript 1.0), HTML5

[11] Opera にはなぜか length がありますが (select の length と同じものを返す)、 IndexGetter はないみたいです。

[12] WinIE7 で new Option して作った option 要素を appendChild しても、なぜか選択肢の名札は何も表示されません。 innerHTML にも名札に相当する文字列はでてきません。 そのせいでしょうか。 そういえば text DOM属性がある要素の扱いが IE DOM では特殊なのと関係あるかもしれません。

add など DOM0 的方法で追加するのは名札も含めてうまくいきます。

[13] Web Applications 1.0 r7785 Option constructor: clean up to use more WebIDL features, behave more like IE for the first argument. Add some rationale for Web Storage disk quota suggestions. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7784&to=7785

[14] Chrome では document.createElement ('option') instanceof HTMLOptionElement は真ですが、 document.createElement ('option') instanceof Option は偽です。 Firefox、WinIE9 では後者も真です。

[15] Image や Audio でも同じです。
[16] HTMLOptionElement === Option はどのブラウザーでも偽です。

Option コンストラクター

[17]

(new Option ())Option (JavaScript 1.0), HTML5

歴史

HTML5

[71] [] (0) WF2: <option> element summary., Hixie, , https://github.com/whatwg/html/commit/bf9bca6fb670a4318e28bb39edcfcdb7b85258aa

[70] HTML要素概説
要素名
option
日付
説明
、 HTML5 に option が追加された。
出典

[172] IRC logs: freenode / #whatwg / 20100926 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20100926

[173] IRC logs: freenode / #whatwg / 20110803 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20110803

[174] Web Applications 1.0 r7786 fix mistake in previous checkin; and fix mistake in much earlier checkin... ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7785&to=7786

[175] HTML - IE と <option> - Qiita [キータ] ( ( 版)) http://qiita.com/wakaba@github/items/c62fba79cbc5cec42251

[176] Web Applications 1.0 r8147 Change how the content models of <title> and <option> are defined (move from prose additions to more formal content model descriptions, and tighten up the requirements) ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8146&to=8147

[177] Web Applications 1.0 r8297 Move more towards the browsers for <option> selectedness vs dirtiness. This doesn't quite match any browser exactly, so all browsers would have to change to match it. If there's a reason (e.g. backcompat) to prefer a different model, please reopen the bug and let me know. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8296&to=8297

[178] Web Applications 1.0 r8341 Updates for r8297, fixing <option> to treat 'dirtiness' correctly, and r8336, fixing 'error' events sent to MessagePort objects to not race messages sent from those ports (or, worse, the event that the port is delivered on...). ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8340&to=8341

[179] ncsa-mosaic/CHANGES at master · alandipert/ncsa-mosaic ( ( 版)) https://github.com/alandipert/ncsa-mosaic/blob/master/CHANGES#L114

[8] [giow] (3) option.text needs to exclude script nodes, for compat reasons · whatwg/html@b1adc35 ( 版) https://github.com/whatwg/html/commit/b1adc35035eff05e6177d11cc5e564934a0cc977

[9] 19549 – option.text should skip script elements ( 版) https://www.w3.org/Bugs/Public/show_bug.cgi?id=19549

[10] Make label-less empty option OK if datalist child · whatwg/html@3885f11 ( 版) https://github.com/whatwg/html/commit/3885f11503431c1bb33c3bb4bf1b9d5d9bcdae61

[18] Fix the owner document for all element constructors ( (domenic著, )) https://github.com/whatwg/html/commit/c9d898386d7b79cf1c7e104b5768e393c924078f

[19] Allow all HTML element constructors to be subclassed (domenic著, ) https://github.com/whatwg/html/commit/4742b18559a6968213b680ea0b0521eae17de7e1

[20] Element containers for OPTION elements are hard. (shs96c著, ) https://github.com/w3c/webdriver/commit/6a8fa1ef8e71d6fdee43ad980e4aa9c75fe33083

[21] 169296 – Label of an <option> element should not be displayed in quirks mode () https://bugs.webkit.org/show_bug.cgi?id=169296

[22] 40545 - (option-label) LABELs don't work for OPTIONs (<option label> in selects) () https://bugzilla.mozilla.org/show_bug.cgi?id=40545

[23] Clarify disabled for option/optgroup is defined separately (annevk著, ) https://github.com/whatwg/html/commit/8d60f070d6ba6b5c7dfbc116fd9d3faee5d9c96e

[24] javascript - iOS safari not showing all options for select menu - Stack Overflow () https://stackoverflow.com/questions/35021620/ios-safari-not-showing-all-options-for-select-menu/41749701

[25] iOS の Safari は label 属性に対応していない。 っていつの時代だよ、糞すぎるにも程があるだろ! これが寡占の弊害やな