Event:bubbles 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Event 接口的 bubbles 只读属性表明事件是否会沿 DOM 树向上冒泡。

备注: 有关冒泡的更多信息,请参阅事件冒泡

一个布尔值,若事件沿 DOM 树向上冒泡,则该属性为 true

示例

js
function handleInput(e) {
  // 检查事件是否沿冒泡阶段传播
  if (!e.bubbles) {
    passItOn(e);
  }

  // 已经冒泡
  doOutput(e);
}

规范

Specification
DOM
# ref-for-dom-event-bubbles③

浏览器兼容性

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
bubbles

Legend

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

Full support
Full support
See implementation notes.

参见

  • stopPropagation() 方法用于阻止当前事件在捕获和冒泡阶段的进一步传播
  • stopImmediatePropagation() 方法用于阻止在同一 DOM 层级上针对同一事件调用任何后续监听器
  • preventDefault() 方法用于在事件继续传播的同时,禁止浏览器在无监听器处理该事件时执行其默认操作