--- title: Event.defaultPrevented slug: Web/API/Event/defaultPrevented translation_of: Web/API/Event/defaultPrevented ---
{{ APIRef("DOM") }}

概述

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

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

語法

bool = event.defaultPrevented 

範例

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

規範

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-event-defaultprevented', 'Event.defaultPrevented()')}} {{ Spec2('DOM WHATWG') }}  
{{SpecName('DOM4', '#dom-event-defaultprevented', 'Event.defaultPrevented')}} {{Spec2('DOM4')}} Initial definition.

瀏覽器相容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatChrome(18) }} {{ CompatGeckoDesktop("6.0") }} {{ CompatIE(9.0) }} {{ CompatOpera(11.0) }} {{ CompatSafari("5.0") }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatGeckoMobile("6.0") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatSafari(5.0) }}