5.3 Event 扩展
优质
小牛编辑
135浏览
2023-12-01
Property | Type | Description |
KEY_BACKSPACE | NumberNumber | 8: Constant. Code for the Backspace key. |
KEY_TAB | Number | 9: Constant. Code for the Tab key. |
KEY_RETURN | Number | 13: Constant. Code for the Return key. |
KEY_ESC | Number | 27: Constant. Code for the Esc key. |
KEY_LEFT | Number | 37: Constant. Code for the Left arrow key. |
KEY_UP | Number | 38: Constant. Code for the Up arrow key. |
KEY_RIGHT | Number | 39: Constant. Code for the Right arrow key. |
KEY_DOWN | Number | 40: Constant. Code for the Down arrow key. |
KEY_DELETE | Number | 46: Constant. Code for the Delete key. |
observers: | Array | List of cached observers. Part of the internal implementation details of the object. |
Method | Kind | Arguments | Description |
element(event) | static | event: an Event object | 返回事件源对象。 |
isLeftClick(event) | static | event: an Event object | 如果点击了鼠标左键,返回true. |
pointerX(event) | static | event: an Event object | 返回鼠标的X座标。 |
pointerY(event) | static | event: an Event object | 返回鼠标的Y座标。 |
stop(event) | static | event: an Event object | 使用此函数来中断事件的默认行为并阻止传递(冒泡)。 |
findElement(event, tagName) | static | event: an Event object, tagName: name of the desired tag. | 从事件源对象开始向上搜索DOM树,直到找到第一个符合tagName的元素 |
observe(element, name, observer, useCapture) | static | element: object or id, name: event name (like 'click', 'load', etc), observer: function to handle the event, useCapture: if true, handles the event in the capture phase and if false in the bubbling phase. | 为对象的某个事件增加一个处理函数。 |
stopObserving(element, name, observer, useCapture) | static | element: object or id, name: event name (like 'click'), observer: function that is handling the event, useCapture: if true handles the event in the capture phase and if false in the bubbling phase. | 和上面的函数相反。 |
_observeAndCache(element, name, observer, useCapture) | static | 私有函数,别管它。 | |
unloadCache() | static | (none) | 私有函数,别管它。从内存中清除所有的observers缓存。 |
下面代码演示如何给window添加一个load事件处理函数。
<script> Event.observe(window, 'load', showMessage, false); function showMessage() { alert('Page loaded.'); } </script>