aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/event/currenttarget
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/event/currenttarget
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/event/currenttarget')
-rw-r--r--files/zh-cn/web/api/event/currenttarget/index.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/event/currenttarget/index.html b/files/zh-cn/web/api/event/currenttarget/index.html
new file mode 100644
index 0000000000..0ed0529962
--- /dev/null
+++ b/files/zh-cn/web/api/event/currenttarget/index.html
@@ -0,0 +1,88 @@
+---
+title: event.currentTarget
+slug: Web/API/Event/currentTarget
+tags:
+ - API
+ - DOM
+ - Event
+ - Property
+ - Read-only
+translation_of: Web/API/Event/currentTarget
+---
+<p>{{APIRef("DOM")}}</p>
+
+<p>{{domxref("Event")}} 接口的只读属性 <code><strong>currentTarget</strong></code> 表示的,标识是当事件沿着 DOM 触发时事件的当前目标。它总是指向事件绑定的元素,而 {{domxref("Event.target")}} 则是事件触发的元素。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="notranslate">var <em>currentEventTarget</em> = <em>event</em>.currentTarget;</pre>
+
+<h3 id="Value">Value</h3>
+
+<p>{{domxref("EventTarget")}}</p>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<p>当将相同的事件处理程序附加到多个元素时 <code>event.currentTarget</code> 就很有用。</p>
+
+<pre class="brush: js notranslate">function hide(e){
+ e.currentTarget.style.visibility = "hidden";
+  console.log(e.currentTarget);
+ // 该函数用作事件处理器时: this === e.currentTarget
+}
+
+var ps = document.getElementsByTagName('p');
+
+for(var i = 0; i &lt; ps.length; i++){
+ // console: 打印被点击的p元素
+ ps[i].addEventListener('click', hide, false);
+}
+// console: 打印body元素
+document.body.addEventListener('click', hide, false);
+</pre>
+
+
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th>Specification</th>
+ <th>Status</th>
+ <th>Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM WHATWG", "#dom-event-currenttarget", "Event.currentTarget")}}</td>
+ <td>{{Spec2("DOM WHATWG")}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM4", "#dom-event-currenttarget", "Event.currentTarget")}}</td>
+ <td>{{Spec2("DOM4")}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM3 Events", "#dfn-current-event-target", "current event target")}}</td>
+ <td>{{Spec2("DOM3 Events")}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName("DOM2 Events", "#Events-Event-currentTarget", "Event.currentTarget")}}</td>
+ <td>{{Spec2("DOM2 Events")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Event.currentTarget")}}</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/Event/Comparison_of_Event_Targets">Comparison of Event Targets</a></li>
+</ul>