UIEvent 接口表示简单的用户界面事件。
UIEvent 是从 Event 派生出来的。尽管 UIEvent.initUIEvent() 方法为了向后兼容而一直保留着,但是你应该使用 UIEvent() 构造器来创建 UIEvent 对象。
某些接口是这个的直接或间接后代:MouseEvent, TouchEvent, FocusEvent, KeyboardEvent, WheelEvent, InputEvent, 和CompositionEvent.
Constructors
UIEvent()- 创建一个
UIEvent对象
属性
也继承了父代 Event 的一些属性。
UIEvent.cancelBubble- 返回一个
Boolean,表示该事件的冒泡是否被取消。
UIEvent.detail只读- Returns a
longwith details about the event, depending on the event type. UIEvent.isChar只读- 返回一个
Boolean,表示该事件是否产生了一个键盘字符(key character)。 UIEvent.layerX只读- 返回事件相对于当前层的水平坐标。
UIEvent.layerY只读- 返回事件相对于当前层的垂直坐标。
UIEvent.pageX只读- 返回事件相对于整个文档的水平坐标。
UIEvent.pageY只读- 返回事件相对于整个文档的垂直坐标。
UIEvent.sourceCapabilities只读- 返回输入设备功能接口的一个实例,它提供有关负责生成 touch 事件的物理设备的信息。
UIEvent.view只读- 返回一个包含了产生该事件的视图的
WindowProxy。 UIEvent.which只读- 返回一个对应(键盘)按下的数字类型的
keyCode,或者一个字母数字键按下时的字符码(charCode)。
方法
也继承了父代 Event 的一些方法。
UIEvent.initUIEvent()- 初始化一个
UIEvent对象。如果事件已经被分派,这个方法什么都不做。
规范
| Specification | Status | Comment |
|---|---|---|
| InputDeviceCapabilities | Editor's Draft | Added sourceCapabilities property. |
| Document Object Model (DOM) Level 3 Events Specification UIEvent |
Obsolete | Added the UIEvent() constructor, deprecated the initUIEvent() method and changed the type of viewfrom AbstractView to WindowProxy. |
| Document Object Model (DOM) Level 2 Events Specification UIEvent |
Obsolete | Initial definition |
浏览器兼容性
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes)[2] | ? | (Yes) | ? |
UIEvent() |
(Yes) | (Yes) | 11 (11) | ? | (Yes) | ? |
cancelBubble defined on Event |
? | (Yes) | 53 (53)[1] | ? | ? | ? |
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes)[2] | ? | (Yes) | ? |
UIEvent() |
(Yes) | (Yes) | 11.0 (11) | ? | (Yes) | ? |
cancelBubble defined on Event |
? | (Yes) | 53.0 (53)[1] | ? | ? | ? |
[1] From Firefox 52, this property is now defined on the Event interface instead. See bug 1298970 for more details.
[2] The 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.