Prototype1.4手册(7)

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> 在prototype.js中定义新的对象和类

另一个这个程序包帮助你的地方就是提供许多既支持面向对象设计理念又有共通功能的许多对象。

The PeriodicalExecuter object

这个对象提供一定间隔时间上重复调用一个方法的逻辑。

Method Kind Arguments Description
[ctor](callback, interval)   constructor   callback: a parameterless function, interval: number of seconds   创建这个对象的实例将会重复调用给定的方法。  

Property Type Description
callback   Function()   被调用的方法,该方法不能传入参数。  
frequency   Number   以秒为单位的间隔。  
currentlyExecuting   Boolean   表示这个方法是否正在执行。  

The Prototype object

Prototype 没有太重要的作用,只是声明了该程序包的版本 。

Property Type Description
Version   String   版本。  
emptyFunction   Function()   空函数。  
K   Function(obj)   一个仅仅回传参数的函数。  
ScriptFragment   String   识别script的正则式。  

The Enumerable object

Enumberable对象能够已更优雅的方式实现对列表样式的结构进行枚举。

很多其它的对象通过扩展自Enumberable对象来得到这些有用的接口。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjjfjs.html