下面两种方法有什么区别吗? #1 比 #2 快吗?
#1
$('#selector').on('click',function(){
$(this)...
// do stuff with clicked element
})
and
#2
$('#selector').on('click',function(e){
$(e.currentTarget)....
// do stuff with clicked element
})
在大多数情况下它们似乎是等效的,尽管“this”似乎更容易输入
根据http://api.jquery.com/event.currentTarget/ http://api.jquery.com/event.currentTarget/
event.currentTarget
该属性通常等于this
的函数。
如果您正在使用jQuery代理 http://api.jquery.com/jQuery.proxy/或另一种形式的范围操纵,this
将等于您提供的任何上下文,而不是event.currentTarget
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)