📜  Prototype-事件处理

📅  最后修改于: 2020-10-21 08:47:03             🧑  作者: Mango


 

事件管理是实现跨浏览器脚本的最大挑战之一。每个浏览器都有不同的方法来处理按键。

Prototype Framework处理所有跨浏览器兼容性问题,使您摆脱与事件管理相关的所有麻烦。

Prototype框架提供了事件命名空间,该命名空间中充斥着各种方法,它们都将当前事件对象作为参数,并在所有主要浏览器中愉快地产生您所请求的信息。

事件名称空间还提供了可与键盘相关的事件使用的键控代码的标准化列表。以下常量在命名空间中定义-

S.No. Key Constant & Description
1. KEY_BACKSPACE

Represent back space key.

2. KEY_TAB

Represent tab key.

3. KEY_RETURN

Represent return key.

4. KEY_ESC

Represent esc key.

5. KEY_LEFT

Represent left key.

6. KEY_UP

Represent up key.

7. KEY_RIGHT

Represent right key.

8. KEY_DOWN

Represent down key.

9. KEY_DELETE

Represent delete key.

10. KEY_HOME

Represent home key.

11. KEY_END

Represent end key.

12. KEY_PAGEUP

Represent page up key.

13. KEY_PAGEDOWN

Represent page down key.

如何处理事件

在开始之前,让我们看一个使用事件方法的例子。本示例说明如何捕获发生事件的DOM元素。

Prototype examples
      
      
      
   

   
      

Click on any part to see the result.

This is paragraph

This is divsion.

输出

这是与Event相关的所有方法的完整列表。您最可能经常使用的功能是观察元素停止

Prototype事件方法

注意-确保您至少具有1.6版的prototype.js。

S.No. Method & Description
1. element()

Returns the DOM element on which the event occurred.

2. extend()

Extends the event with all of the methods contained in Event.Methods.

3. findElement()

Returns the first DOM element with a given tag name, upwards from the one on which the event occurred.

4. isLeftClick()

Determines whether a button-related mouse event was about the “left” (primary, actually) button.

5. observe()

Registers an event handler on a DOM element.

6. pointerX()

Returns the absolute horizontal position for a mouse event.

7. pointerY()

Returns the absolute vertical position for a mouse event.

8. stop()

Stops the event’s propagation and prevents its default action from being triggered eventually.

9. stopObserving()

Unregisters an event handler.

10. unloadCache()

Unregisters all event handlers registered through observe. Automatically wired for you. Not available since 1.6.