Event:cancelBubble 属性

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

备注: 此特性在 Web Worker 中可用。

Event 接口的 cancelBubble 属性已被弃用。请使用 Event.stopPropagation() 代替。在事件处理器返回之前将其值设置为 true 可以阻止事件的传播。在后续的实现中,将其设置为 false 不会产生任何效果。请参阅浏览器兼容性了解详细信息。

布尔值。值为 true 表示事件不得继续传播。

示例

js
elem.onclick = (event) => {
  // 在这里做一些很酷的事情
  event.cancelBubble = true;
};

规范

Specification
DOM
# ref-for-dom-event-cancelbubble①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
cancelBubble
Deprecated

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Deprecated. Not for use in new websites.
See implementation notes.
Has more compatibility info.