* onblur 属性 (HTML, XHTML 1)

[1] [ABBR[[[HTML]]] [Hypertext Markup Language]] の 
[DFN[[CODE(HTMLa)[onblur]] 属性]]は、
[RUBYB[指示装置] [pointing device]]によって、
またはタブ操作 ([CODE(HTMLa)[[[tabindex]]]] を参照してください。) 
によって[[要素]]が[[焦点]]を失った時に発生する[[事象]]に関する[[内在事象]]属性です。

適用対象要素型:
- [CODE(HTMLe)[[[a]]]]
- [CODE(HTMLe)[[[area]]]]
- [CODE(HTMLe)[[[label]]]]
- [CODE(HTMLe)[[[input]]]]
- [CODE(HTMLe)[[[textarea]]]]
- [CODE(HTMLe)[[[select]]]]
- [CODE(HTMLe)[[[button]]]]

[2] 仕様書:
- [[HTML 4]]
-- [CODE(HTMLa)[onblur]] 属性
<IW:HTML4:"interact/scripts.html#adef-onblur">

** 代替

[3] 内在事象属性は[[表現と構造の分離]]の原則に反するので、
好ましくないと考える人もいます。また、 
[ABBR[DOM] [Document Object Model]] 水準 0 ([[DOM 0]])
に基づく古い設計です。

代わりに、 [CODE(HTMLe)[[[script]]]] 要素などにより関連付けたスクリプト内で
[[DOM 2]] 以上の[[事象]]に関するメソッド等が利用できます。
DOM 水準2 や DOM 水準 3 はこの属性に対応する
DOM の事象 [CODE(DOM)[[VAR[ev:]][[DOMFocusOut]]]] を用意しています。

[[#comment]]


** 属性値

[4] この属性の値は [CODE(SGML)[%[[Script]]]] です。 
[ABBR[[[SGML]]] [Standard Generalized Markup Language]]
的には [CODE(SGML)[[[CDATA]]]] です。
自称が発生したときに実行するスクリプトの code
を記述します。[[スクリプト言語]]は、
[CODE(HTTP)[[[Content-Script-Type]]]] によります。

[5] この属性は省略可能です。

[[#comment]]


** 他との関係

[6] この属性に対応する DOM の事象は [CODE(DOM)[[VAR[ev:]][[DOMFocusOut]]]]
です。そちらもあわせてごらんください。

[7] 逆に焦点を得た時には [CODE(HTMLa)[[[onfocus]]]] 
事象が発生します。

[[#comment]]


* 例

[8] 入力内容を確認する例 [SRC[HTML 4 18.2.3]]
[PRE(HTML)[
<INPUT NAME="userName" onblur="validUserName(this.value)">
]PRE]

この例では、利用者が入力欄から離れようとすると、
関数 [CODE[validUserName]] が呼ばれ、
妥当な値であるか否かを確認します。



* HTML もどき

[24] [CODE[onBlur]] [[属性]]は [[NCX]] にもありましたが、詳細な説明がなく不明です。

[25] [CITE@en-US[DAISY ANSI/NISO Z39.86-2002 - The DAISY Consortium]], [TIME[2023-11-26T05:54:52.000Z]] <https://daisy.org/info-help/document-archive/archived-projects/daisy-ansi-niso-z39-86-2002-archived/#NCXDTD>


* 歴史

[13]
[CITE[onBlurの発生タイミングについて]]
<http://chaichan.hp.infoseek.co.jp/qa3000/qa3114.htm>

[CODE(HTMLa)@en[[[onblur]]]] と [CODE(HTMLa)@en[[[onfocus]]]]
の順序について。


[14] [CITE@en[Web Applications 1.0 r8621     Spec relatedTarget for focus and blur]]
( ([TIME[2014-05-09 05:13:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8620&to=8621>

[9] [CITE@en[559561 – When focused element is removed, fire blur event on it]]
([TIME[2015-07-28 11:36:00 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=559561>

[10] [CITE@en[Don't repeat events defined in other specs. · w3c/svgwg@ba6ff23]]
([TIME[2016-02-06 12:34:15 +09:00]] 版)
<https://github.com/w3c/svgwg/commit/ba6ff23e1e90914465633294eebc091f6065e0d6>

[11] [CITE@en[Meta: disambiguate focus() and blur() for Window and HTMLElement]]
([[zcorpan]]著, [TIME[2017-10-20 10:21:55 +09:00]])
<https://github.com/whatwg/html/commit/fde99312b1f788dbdd3bd7579ca8c40a067d5d50>

[12] [CITE@en[Meta: Disambiguate focus() and blur() for Window and HTMLElement by zcorpan · Pull Request #3138 · whatwg/html]]
([TIME[2017-10-21 16:22:56 +09:00]])
<https://github.com/whatwg/html/pull/3138>

[15] [CITE@en[Mark focus events composed]]
([[annevk]]著, [TIME[2018-03-02 17:20:50 +09:00]])
<https://github.com/whatwg/html/commit/84d96dfd816f5e6f229df0558ce10af26482bfc5>

[16] [CITE@en[Make focus events composed · Issue #3511 · whatwg/html]]
([TIME[2018-03-03 12:43:05 +09:00]])
<https://github.com/whatwg/html/issues/3511>

[17] [CITE@en[Mark focus events composed by annevk · Pull Request #3512 · whatwg/html]]
([TIME[2018-03-03 12:43:38 +09:00]])
<https://github.com/whatwg/html/pull/3512>

[18] [CITE@en[Add HTMLOrSVGElement interface mixin]]
([[annevk]]著, [TIME[2018-03-23 19:30:45 +09:00]])
<https://github.com/whatwg/html/commit/81e82437a7ef1ee37d4ce2b5a982bc297d5b58b1>

[19] [CITE@en[Move dataset from HTMLElement to a mixin shared with SVGElement · Issue #3471 · whatwg/html]]
([TIME[2018-03-24 17:58:52 +09:00]])
<https://github.com/whatwg/html/issues/3471>

[20] [CITE@en[Add HTMLOrSVGElement interface mixin by annevk · Pull Request #3543 · whatwg/html]]
([TIME[2018-03-24 18:04:12 +09:00]])
<https://github.com/whatwg/html/pull/3543>

[21] [CITE@en[Add HTMLOrSVGElement mixn]]
([[dstorey]]著, [TIME[2018-04-18 09:31:56 +09:00]])
<https://github.com/w3c/svgwg/commit/bf070f6e46face7169561d4ea7dae45b93210dfb>

[22] [CITE@en[Clarify Window's focus() and blur()]]
([[annevk]]著, [TIME[2019-02-23 01:14:08 +09:00]])
<https://github.com/whatwg/html/commit/12969e1c0a9a95eab967fd1505eb4197ecdd5653>

[23] [CITE@en[Clarify Window's focus() and blur() by annevk · Pull Request #4377 · whatwg/html]]
([TIME[2019-07-15 20:24:37 +09:00]])
<https://github.com/whatwg/html/pull/4377>