event.stopPropagation

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

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

如果要停止这些行为,请参见 preventDefault 方法,它可以阻止事件触发后默认动作的发生。

语法

event.stopPropagation(); 

参数

None.

返回值

undefined.

例子

查看示例5: 事件传播 在示例一章中有关此方法和事件在DOM中传播的更详细示例。

备注

查看 DOM 规范 中关于事件流的解释。 ( DOM Level 3 事件草案 有案例可参考。)

preventDefault 是另外一个相关的方法,它可以阻止事件触发后默认动作的发生。

规范

规范 状态 说明
DOM4
Event.stopPropagation()
Obsolete
Document Object Model (DOM) Level 3 Events Specification
Event.stopPropagation()
Obsolete
Document Object Model (DOM) Level 2 Events Specification
Event.stopPropagation()
Obsolete 初始定义

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
stopPropagationChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 9Opera Full support 7Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0

Legend

Full support  
Full support