--- title: Event.defaultPrevented slug: Web/API/Event/defaultPrevented translation_of: Web/API/Event/defaultPrevented ---
回傳一個布林值,表示事件的預設行為是否被取消,也就是事件物件是否曾執行 {{domxref("event.preventDefault()", "preventDefault()")}} 方法。
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) }} |