aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/blur_event/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/element/blur_event/index.html')
-rw-r--r--files/zh-cn/web/api/element/blur_event/index.html150
1 files changed, 150 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/blur_event/index.html b/files/zh-cn/web/api/element/blur_event/index.html
new file mode 100644
index 0000000000..a57cc5b995
--- /dev/null
+++ b/files/zh-cn/web/api/element/blur_event/index.html
@@ -0,0 +1,150 @@
+---
+title: blur (event)
+slug: Web/Events/blur
+translation_of: Web/API/Element/blur_event
+---
+<p>当一个元素失去焦点的时候 blur 事件被触发。它和 <a href="/en-US/docs/Mozilla_event_reference/focusout"><code>focusout</code></a> 事件的主要区别是 focusout 支持冒泡。</p>
+
+<h2 id="常规信息">常规信息</h2>
+
+<dl>
+ <dt style="float: left; text-align: right; width: 120px;">规范</dt>
+ <dd style="margin: 0 0 0 120px;"><a class="external" href="http://www.w3.org/TR/DOM-Level-3-Events/#event-type-blur">DOM L3</a></dd>
+ <dt style="float: left; text-align: right; width: 120px;">接口</dt>
+ <dd style="margin: 0 0 0 120px;">{{domxref("FocusEvent")}}</dd>
+ <dt style="float: left; text-align: right; width: 120px;">是否冒泡</dt>
+ <dd style="margin: 0 0 0 120px;">否</dd>
+ <dt style="float: left; text-align: right; width: 120px;">可取消默认行为</dt>
+ <dd style="margin: 0 0 0 120px;">否</dd>
+ <dt style="float: left; text-align: right; width: 120px;">目标对象</dt>
+ <dd style="margin: 0 0 0 120px;">元素(Element)</dd>
+ <dt style="float: left; text-align: right; width: 120px;">默认行为</dt>
+ <dd style="margin: 0 0 0 120px;">无</dd>
+</dl>
+
+<p>{{NoteStart}}{{domxref("Document.activeElement")}} 的值随浏览器的不同而不同 ({{bug(452307)}}): IE10把值设为焦点将要移向的对象 , 而Firefox和Chrome 往往把值设为<code>body</code> .{{NoteEnd}}</p>
+
+<h2 id="属性">属性</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">属性</th>
+ <th scope="col">类型</th>
+ <th scope="col">描述</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>target</code> {{readonlyInline}}</td>
+ <td>{{domxref("EventTarget")}}</td>
+ <td>产生该事件的对象(DOM树中最顶级的那个对象).</td>
+ </tr>
+ <tr>
+ <td><code>type</code> {{readonlyInline}}</td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>事件类型.</td>
+ </tr>
+ <tr>
+ <td><code>bubbles</code> {{readonlyInline}}</td>
+ <td>{{jsxref("Boolean")}}</td>
+ <td>该事件是否冒泡.</td>
+ </tr>
+ <tr>
+ <td><code>cancelable</code> {{readonlyInline}}</td>
+ <td>{{jsxref("Boolean")}}</td>
+ <td>该事件是否可取消默认行为.</td>
+ </tr>
+ <tr>
+ <td><code>relatedTarget</code> {{readonlyInline}}</td>
+ <td>{{domxref("EventTarget")}} (DOM 元素)</td>
+ <td>无</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="事件代理">事件代理</h2>
+
+<p>有两种方法来为这个事件实现事件代理:在支持 <code>focusout</code> 事件的浏览器中使用 focusout 事件(除了 FireFox 以外的浏览器都支持 focusout)或者通过设置 <a href="/en-US/docs/DOM/element.addEventListener"><code>addEventListener</code></a> 方法的第三个参数 "useCapture" 为 <code>true:</code></p>
+
+<h3 id="HTML_Content">HTML Content</h3>
+
+<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>
+
+<h3 id="JavaScript_Content">JavaScript Content</h3>
+
+<pre class="brush: js">var form = document.getElementById("form");
+form.addEventListener("focus", function( event ) {
+ event.target.style.background = "pink";
+}, true);
+form.addEventListener("blur", function( event ) {
+ event.target.style.background = "";
+}, true);</pre>
+
+<p>{{EmbedLiveSample('Event_delegation')}}</p>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>5</td>
+ <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
+ <td>6</td>
+ <td>12.1</td>
+ <td>5.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>4.0</td>
+ <td>53</td>
+ <td>{{CompatUnknown}}</td>
+ <td>10.0</td>
+ <td>12.1</td>
+ <td>5.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 在 Gecko 24 {{geckoRelease(24)}} 之前,事件的接口为 {{domxref("Event")}},而不是 {{domxref("FocusEvent")}}。参考 ({{bug(855741)}}).</p>
+
+<h2 id="相关的事件">相关的事件</h2>
+
+<ul>
+ <li>{{event("focus")}}</li>
+ <li>{{event("blur")}}</li>
+ <li>{{event("focusin")}}</li>
+ <li>{{event("focusout")}}</li>
+</ul>