event.defaultPrevented

Baseline Widely available

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

概述

返回一个布尔值,表明当前事件是否调用了 event.preventDefault()方法。

备注:你应该使用该属性来代替以前的非标准的已经被废弃的getPreventDefault()方法 (查看Firefox bug 691151).

语法

js
bool = event.defaultPrevented;

示例

js
if (e.defaultPrevented) {
  /* 事件的默认动作已被取消*/
}

规范

Specification
DOM Standard
# ref-for-dom-event-defaultprevented①

浏览器兼容性

BCD tables only load in the browser