From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/globaleventhandlers/onblur/index.html | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 files/ja/web/api/globaleventhandlers/onblur/index.html (limited to 'files/ja/web/api/globaleventhandlers/onblur') diff --git a/files/ja/web/api/globaleventhandlers/onblur/index.html b/files/ja/web/api/globaleventhandlers/onblur/index.html new file mode 100644 index 0000000000..a5dc8cb510 --- /dev/null +++ b/files/ja/web/api/globaleventhandlers/onblur/index.html @@ -0,0 +1,91 @@ +--- +title: GlobalEventHandlers.onblur +slug: Web/API/GlobalEventHandlers/onblur +tags: + - API + - HTML DOM + - NeedsMarkupWork + - Property + - Reference +translation_of: Web/API/GlobalEventHandlers/onblur +--- +
{{ApiRef("HTML DOM")}}
+ +

{{domxref("GlobalEventHandlers")}} ミックスインの onblur プロパティは、{{event("blur")}} イベントを処理する {{domxref("EventHandler")}} です。これは、{{domxref("Element")}}、{{domxref("Document")}}、{{domxref("Window")}} 上で利用できます。

+ +

blur イベントは要素がフォーカスを失ったときに生じます。

+ +
+

補足: onblur の反対が {{domxref("GlobalEventHandlers.onfocus", "onfocus")}} です。

+
+ +

構文

+ +
target.onblur = functionRef;
+
+ +

+ +

functionRef は関数名または 関数式 です。この関数は、{{domxref("FocusEvent")}} オブジェクトとその 1 個の引数を受け取ります。

+ +

+ +

この例は、onblur および {{domxref("GlobalEventHandlers.onfocus", "onfocus")}} を使用して {{HtmlElement("input")}} 要素内のテキストを変更します。

+ +

HTML

+ +
<input type="text" value="ここをクリック">
+
+ +

JavaScript

+ +
let input = document.querySelector('input');
+
+input.onblur = inputBlur;
+input.onfocus = inputFocus;
+
+function inputBlur() {
+  input.value = 'Focus has been lost';
+}
+
+function inputFocus() {
+  input.value = 'Focus is here';
+}
+ +

実行結果

+ +

フォームフィールドの内側と外側をクリックしてみてください。それに応じてコンテンツが変化するか観察してください。

+ +

{{EmbedLiveSample('Example')}}

+ +

仕様

+ + + + + + + + + + + + + + +
仕様書策定状況備考
{{SpecName('HTML WHATWG','webappapis.html#handler-onblur','onblur')}}{{Spec2('HTML WHATWG')}}
+ +

ブラウザー実装状況

+ + + +

{{Compat("api.GlobalEventHandlers.onblur")}}

+ +

IE とは対称的に、blur イベントを受け取るほとんどすべての要素では、Gecko ブラウザー上のほとんどすべての要素において、このイベントが動作しません。

+ +

関連項目

+ + -- cgit v1.2.3-54-g00ecf