aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/event/stoppropagation/index.html
blob: 652231306b18d7d7e3e41d89e8dbd57eeecf9e45 (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
---
title: Event.stopPropagation()
slug: Web/API/Event/stopPropagation
tags:
  - API
  - DOM
  - Event
  - Method
  - NeedsRewrite
  - Reference
translation_of: Web/API/Event/stopPropagation
---
<div>{{APIRef("DOM")}}</div>

<p>{{domxref("Event")}} 介面的 <strong><code>stopPropagation()</code></strong> 方法可阻止當前事件繼續進行捕捉(capturing)及冒泡(bubbling)階段的傳遞。</p>

<h2 id="語法">語法</h2>

<pre class="syntaxbox"><em>event</em>.stopPropagation();</pre>

<h2 id="範例">範例</h2>

<p>請參考範例五:<a href="https://developer.mozilla.org/en-US/docs/DOM/DOM_Reference/Examples#Example_5:_Event_Propagation">事件傳遞</a>章節中關於此方法與 DOM 事件傳遞的更詳細範例。</p>

<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-stoppropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM WHATWG")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("DOM4", "#dom-event-stoppropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM4")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 Events", "#Events-Event-stopPropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM2 Events")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>



<p>{{Compat("api.Event.stopPropagation")}}</p>

<h2 id="參見">參見</h2>

<ul>
 <li>See the <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-capture">DOM specification</a> for the explanation of event flow. (The <a href="http://www.w3.org/TR/DOM-Level-3-Events/#event-flow">DOM Level 3 Events draft</a> has an illustration.)</li>
 <li>{{domxref("Event.preventDefault()")}} is a related method that prevents the default action of the event from happening.</li>
</ul>