aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/element/blur_event/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/web/api/element/blur_event/index.html')
-rw-r--r--files/ja/web/api/element/blur_event/index.html142
1 files changed, 142 insertions, 0 deletions
diff --git a/files/ja/web/api/element/blur_event/index.html b/files/ja/web/api/element/blur_event/index.html
new file mode 100644
index 0000000000..c5ab2b5687
--- /dev/null
+++ b/files/ja/web/api/element/blur_event/index.html
@@ -0,0 +1,142 @@
+---
+title: 'Element: blur イベント'
+slug: Web/API/Element/blur_event
+tags:
+ - API
+ - DOM
+ - Element
+ - Event
+ - FocusEvent
+ - Reference
+ - blur
+ - onblur
+ - イベント
+translation_of: Web/API/Element/blur_event
+---
+<div>{{APIRef}}</div>
+
+<p><strong><code>blur</code></strong> イベントは、要素がフォーカスを失ったときに発生します。このイベントと {{domxref("Element/focusout_event", "focusout")}} との違いは、 <code>focusout</code> が<a href="/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture">バブリング</a>を行うのに対し <code>blur</code> は行わないことです。</p>
+
+<p><code>blur</code> の反対は {{domxref("Element/focus_event", "focus")}} です。</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">バブリング</th>
+ <td>なし</td>
+ </tr>
+ <tr>
+ <th scope="row">キャンセル</th>
+ <td>不可</td>
+ </tr>
+ <tr>
+ <th scope="row">インターフェイス</th>
+ <td>{{DOMxRef("FocusEvent")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">イベントハンドラープロパティ</th>
+ <td>{{domxref("GlobalEventHandlers/onblur", "onblur")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">同期 / 非同期</th>
+ <td>同期</td>
+ </tr>
+ <tr>
+ <th scope="row">Composed</th>
+ <td>はい</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Examples" name="Examples">例</h2>
+
+<h3 id="Simple_example" name="Simple_example">簡単な例</h3>
+
+<h4 id="HTML">HTML</h4>
+
+<pre class="brush:html;">&lt;form id="form"&gt;
+ &lt;input type="text" placeholder="text input"&gt;
+ &lt;input type="password" placeholder="password"&gt;
+&lt;/form&gt;</pre>
+
+<h4 id="JavaScript">JavaScript</h4>
+
+<pre class="brush: js">const password = document.querySelector('input[type="password"]');
+
+password.addEventListener('focus', (event) =&gt; {
+ event.target.style.background = 'pink';
+});
+
+password.addEventListener('blur', (event) =&gt; {
+ event.target.style.background = '';
+});</pre>
+
+<h4 id="Result" name="Result">結果</h4>
+
+<p>{{EmbedLiveSample("Simple_example", '100%', '50px')}}</p>
+
+<h3 id="Event_delegation" name="Event_delegation">イベント委譲</h3>
+
+<p>このイベントのイベント委譲を実装する方法は二つあります。 {{Event("focusout")}} イベントを使用するか、 {{domxref("EventTarget.addEventListener()", "addEventListener()")}} の <code>useCapture</code> 引数に <code>true</code> を設定するかです。</p>
+
+<h4 id="HTML_2">HTML</h4>
+
+<pre class="brush: html">&lt;form id="form"&gt;
+ &lt;input type="text" placeholder="text input"&gt;
+ &lt;input type="password" placeholder="password"&gt;
+&lt;/form&gt;</pre>
+
+<h4 id="JavaScript_2">JavaScript</h4>
+
+<pre class="brush: js">const form = document.getElementById('form');
+
+form.addEventListener('focus', (event) =&gt; {
+ event.target.style.background = 'pink';
+}, true);
+
+form.addEventListener('blur', (event) =&gt; {
+ event.target.style.background = '';
+}, true);</pre>
+
+<h4 id="Result_2" name="Result_2">結果</h4>
+
+<p>{{EmbedLiveSample("Event_delegation", '100%', '50px')}}</p>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ <th scope="col">状態</th>
+ <th scope="col">備考</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("UI Events", "#event-type-blur")}}</td>
+ <td>{{Spec2("UI Events")}}</td>
+ <td>Added info that this event is composed.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM3 Events", "#event-type-blur")}}</td>
+ <td>{{Spec2("DOM3 Events")}}</td>
+ <td>初回定義</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
+
+<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
+
+<p>{{Compat("api.Element.blur_event")}}</p>
+
+<p>このイベントが処理されている間、 {{DOMxRef("Document.activeElement")}} の値はブラウザーによって異なります ({{bug(452307)}})。 IE10 はフォーカスが移動する先の要素を設定しますが、 Firefox および Chrome はふつう、文書の <code>body</code> を設定します。</p>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li>関連イベント: {{domxref("Element/focus_event", "focus")}}, {{domxref("Element/focusin_event", "focusin")}}, {{domxref("Element/focusout_event", "focusout")}}</li>
+ <li><code>Window</code> を対象としたこのイベント: {{domxref("Window/blur_event", "blur")}} イベント</li>
+</ul>