aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/event/stoppropagation/index.html
blob: f494423b47070d4b16799c8d46d429799abb56b3 (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
---
title: event.stopPropagation
slug: Web/API/Event/stopPropagation
tags:
  - API
  - DOM
  - Event
  - stopPropagation
  - 事件
  - 方法
  - 阻止冒泡事件
translation_of: Web/API/Event/stopPropagation
---
<p>{{APIRef("DOM")}}</p>

<p>阻止捕获和冒泡阶段中当前事件的进一步传播。  </p>

<p>但是,它不能防止任何默认行为的发生; 例如,对链接的点击仍会被处理。</p>

<p>如果要停止这些行为,请参见 <a href="/zh-cn/DOM/event.preventDefault" title="zh-cn/DOM/event.preventDefault">preventDefault</a> 方法,它可以阻止事件触发后默认动作的发生。</p>

<h2 id="Syntax" name="Syntax">语法</h2>

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

<h3 id="参数">参数</h3>

<p>None.</p>

<h3 id="返回值">返回值</h3>

<p>undefined.</p>

<h2 id="Example" name="Example">例子</h2>

<p>查看示例5: <a href="/zh-cn/Gecko_DOM_Reference/Examples#Example_5:_Event_Propagation" title="zh-cn/Gecko_DOM_Reference/Examples#Example_5:_Event_Propagation">事件传播</a> 在示例一章中有关此方法和事件在DOM中传播的更详细示例。</p>

<h2 id="Notes" name="Notes">备注</h2>

<p>查看 <a class="external" href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-capture">DOM 规范</a> 中关于事件流的解释。 ( <a class="external" href="http://www.w3.org/TR/DOM-Level-3-Events/#event-flow" title="http://www.w3.org/TR/DOM-Level-3-Events/#event-flow">DOM Level 3 事件草案</a> 有案例可参考。)</p>

<p><a href="/zh-cn/DOM/event.preventDefault" title="zh-cn/DOM/event.preventDefault">preventDefault</a> 是另外一个相关的方法,它可以阻止事件触发后默认动作的发生。</p>

<h2 id="Specification" name="Specification">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th>规范</th>
   <th>状态</th>
   <th>说明</th>
  </tr>
  <tr>
   <td>{{SpecName("DOM4", "#dom-event-stoppropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM4")}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("DOM3 Events", "#widl-Event-stopPropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM3 Events")}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 Events", "#Events-Event-stopPropagation", "Event.stopPropagation()")}}</td>
   <td>{{Spec2("DOM2 Events")}}</td>
   <td>初始定义</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性" style="margin-bottom: 20px; line-height: 30px; font-size: 2.14285714285714rem;">浏览器兼容性</h2>

<div class="hidden">
<p>The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
</div>

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

<div id="compat-desktop"></div>