此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

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 ⁨2015年7月⁩.

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

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

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

示例

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

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

规范

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

浏览器兼容性

参见

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