--- title: GlobalEventHandlers.onblur slug: Web/API/GlobalEventHandlers/onblur tags: - API - HTML DOM - NeedsMarkupWork - Property - Reference translation_of: Web/API/GlobalEventHandlers/onblur --- <div>{{ApiRef("HTML DOM")}}</div> <p>{{domxref("GlobalEventHandlers")}} ミックスインの <code><strong>onblur</strong></code> プロパティは、{{event("blur")}} イベントを処理する {{event("Event_handlers", "event handler")}} です。これは、{{domxref("Element")}}、{{domxref("Document")}}、{{domxref("Window")}} 上で利用できます。</p> <p><code>blur</code> イベントは要素がフォーカスを失ったときに生じます。</p> <div class="blockIndicator note"> <p><strong>補足:</strong> <code>onblur</code> の反対が {{domxref("GlobalEventHandlers.onfocus", "onfocus")}} です。</p> </div> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox"><em>target</em>.onblur = <em>functionRef</em>; </pre> <h3 id="Value" name="Value">値</h3> <p><code>functionRef</code> は関数名または <a href="/ja/docs/Web/JavaScript/Reference/Operators/function">関数式</a> です。この関数は、{{domxref("FocusEvent")}} オブジェクトとその 1 個の引数を受け取ります。</p> <h2 id="Example" name="Example">例</h2> <p>この例は、<code>onblur</code> および {{domxref("GlobalEventHandlers.onfocus", "onfocus")}} を使用して {{HtmlElement("input")}} 要素内のテキストを変更します。</p> <h3 id="HTML">HTML</h3> <pre class="brush: html"><input type="text" value="ここをクリック"> </pre> <h3 id="JavaScript">JavaScript</h3> <pre class="brush: js">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'; }</pre> <h3 id="Result_2" name="Result_2">実行結果</h3> <p>フォームフィールドの内側と外側をクリックしてみてください。それに応じてコンテンツが変化するか観察してください。</p> <p id="Result">{{EmbedLiveSample('Example')}}</p> <h2 id="Specifications" name="Specifications">仕様</h2> <table class="spectable standard-table"> <tbody> <tr> <th scope="col">仕様書</th> <th scope="col">策定状況</th> <th scope="col">備考</th> </tr> <tr> <td>{{SpecName('HTML WHATWG','webappapis.html#handler-onblur','onblur')}}</td> <td>{{Spec2('HTML WHATWG')}}</td> <td> </td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2> <p>{{Compat("api.GlobalEventHandlers.onblur")}}</p> <p>IE とは対称的に、<code>blur</code> イベントを受け取るほとんどすべての要素では、Gecko ブラウザー上のほとんどすべての要素において、このイベントが動作しません。</p> <h2 id="See_also" name="See_also">関連項目</h2> <ul> <li>{{event("blur")}} イベント</li> <li>関連するイベントハンドラー: {{domxref("GlobalEventHandlers.onfocus")}}</li> </ul>