--- title: UIEvent slug: Web/API/UIEvent tags: - 待翻譯 translation_of: Web/API/UIEvent ---

{{APIRef("DOM Events")}}

UIEvent 介面是使用者介面的事件的基本型態。

UIEvent 是從 {{domxref("Event")}} 衍伸過來。 雖然為了相容性,仍留著 {{domxref("UIEvent.initUIEvent()")}} 方法,建立 UIEvent 物件最好是選擇以 {{domxref("UIEvent.UIEvent", "UIEvent()")}} constructor 建立。

許多介面直接或間接繼承此介面,例如:{{domxref("MouseEvent")}}、{{domxref("TouchEvent")}}、{{domxref("FocusEvent")}}、{{domxref("KeyboardEvent")}}、{{domxref("WheelEvent")}}、{{domxref("InputEvent")}} 和 {{domxref("CompositionEvent")}}。

建構式

{{domxref("UIEvent.UIEvent()", "UIEvent()")}}
建立一個 UIEvent 物件 。

屬性

此介面亦繼承其父-- {{domxref("Event")}} 的屬性:

{{domxref("UIEvent.cancelBubble")}} {{Non-standard_inline}} {{Deprecated_inline}}
Is a {{jsxref("Boolean")}} indicating whether the bubbling of the event has been canceled or not.
{{domxref("UIEvent.detail")}}{{readonlyinline}}
Returns a long with details about the event, depending on the event type.
{{domxref("UIEvent.isChar")}} {{obsolete_inline}} {{readonlyinline}}
Returns a {{jsxref("Boolean")}} indicating whether the event produced a key character or not.
{{domxref("UIEvent.layerX")}} {{Non-standard_inline}} {{readonlyinline}}
Returns the horizontal coordinate of the event relative to the current layer.
{{domxref("UIEvent.layerY")}} {{Non-standard_inline}} {{readonlyinline}}
Returns the vertical coordinate of the event relative to the current layer.
{{domxref("UIEvent.pageX")}} {{Non-standard_inline}} {{readonlyinline}}
Returns the horizontal coordinate of the event relative to the whole document.
{{domxref("UIEvent.pageY")}} {{Non-standard_inline}} {{readonlyinline}}
Returns the vertical coordinate of the event relative to the whole document.
{{domxref("UIEvent.sourceCapabilities")}} {{non-standard_inline}} {{readonlyinline}}
Returns an instance of the InputDeviceCapabilities interface which provides information about the physical device responsible for generating a touch event.
{{domxref("UIEvent.view")}}{{readonlyinline}}
Returns a {{domxref("WindowProxy")}} that contains the view that generated the event.
{{domxref("UIEvent.which")}} {{Non-standard_inline}} {{readonlyinline}}
Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.

方法

此介面亦繼承其父-- {{domxref("Event")}} 的方法:

{{domxref("UIEvent.initUIEvent()")}} {{deprecated_inline}}
初始化 UIEvent 物件。若該事件已經觸發的話,此方法就不會執行任何東西。

規範

Specification Status Comment
{{SpecName('InputDeviceCapabilities')}} {{Spec2('InputDeviceCapabilities')}} Added sourceCapabilities property.
{{SpecName('DOM3 Events', '#interface-UIEvent', 'UIEvent')}} {{Spec2('DOM3 Events')}} Added the UIEvent() constructor, deprecated the initUIEvent() method and changed the type of view from AbstractView to WindowProxy.
{{SpecName('DOM2 Events', '#Events-UIEvent', 'UIEvent')}} {{Spec2('DOM2 Events')}} Initial definition

瀏覽器相容性

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}[2] {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
UIEvent() {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(11)}} {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
cancelBubble defined on Event {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(53)}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}[2] {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
UIEvent() {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(11)}} {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
cancelBubble defined on Event {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(53)}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] From Firefox 52, this property is now defined on the {{domxref("Event")}} interface instead. See {{bug(1298970)}} for more details.

[2] The {{domxref("UIEvent.isChar", "isChar")}} property has never been supported by any browser but Firefox, and even on Firefox it's never worked except on Mac OSX. For that reason, it's been removed in Firefox 55 to align with other browsers.

參見