mootools_在MooTools 1.2.3中实现Element.hasEvent

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中实现此功能的绝佳用例,但是您可以随意使用它。

翻译自: https://davidwalsh.name/element-has-event

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值