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 July 2015.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

概述

回傳一個布林值,表示事件的預設行為是否被取消,也就是事件物件是否曾執行 preventDefault() 方法。

備註: You should use this instead of the non-standard, deprecated getPreventDefault() method (see Firefox bug 691151).

語法

js
bool = event.defaultPrevented;

範例

js
if (e.defaultPrevented) {
  /* the default was prevented */
}

規範

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

瀏覽器相容性