mootools
MooTools allows you to easily add event listeners to elements using the addEvent and removeEvent methods. One thing MooTools doesn't have is a hasEvent method which will check an element's list of listeners to see if the element has been assigned a specific function per event. I experimented with implementing this functionality and believe I've found the best solution.
MooTools允许您使用addEvent和removeEvent方法轻松地将事件侦听器添加到元素。 MooTools没有的一件事是hasEvent方法,该方法将检查元素的侦听器列表以查看是否为每个事件为元素分配了特定功能。 我尝试实现此功能,并相信找到了最佳解决方案。
MooTools JavaScript (The MooTools JavaScript)
Element.implement({ hasEvent: function(eventType,fn) { //get the element's events var myEvents = this.retrieve('events'); //can we shoot this down? return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn)); }});
The code is quite short. I can't provide a great use case for implementing this in the MooTools Core but it's a lovely little snippet to have at your disposal.
代码很短。 我无法提供在MooTools Core中实现此功能的绝佳用例,但是您可以随意使用它。
翻译自:
mootools