aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/globaleventhandlers/onblur/index.html
blob: a5dc8cb510edb82f18ce8201318376274695b130 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
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")}} イベントを処理する {{domxref("EventHandler")}} です。これは、{{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">&lt;input type="text" value="ここをクリック"&gt;
</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>