使用 $(this) 与 this 之间的根本区别是什么
$('.viewComments').click(function(ev){
//returns the desired value
alert(this.getAttribute('id'));
//Gives an error sayin function is not defined
alert($(this).getAttribute('id'));
//returns the desired value
alert($(this).attr('id'));
});
我认为“$(this)”将包含“this”具有的所有功能以及更多..但事实似乎并非如此。
那么 $(this) 到底是什么?和
我在使用时如何知道有哪些功能可用? (我知道我可以通过萤火虫获得它们。但我想知道是否还有其他方法 - 可能有一些文档)
this
是 DOM 对象,而$(this)
jQuery 包装器是一样的。
使用时this
,您可以对其调用 DOM 方法,但不能调用 jQuery 方法。使用时$(this)
,您可以对其调用 jQuery 方法,但不能调用 DOM 方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)