在jQuery中,this和$(this)有什么区别?在什么情况下应该使用它们?
$('p').each(function () {
//this.id;
//$(this).attr('id');
})
$(this).find('span')
。单独的“this”对象只是一个普通的Javscript DOM对象。this
返回一个本地的 JavaScript 对象(如果我调用正确的话),$(this)
返回一个 jQuery 对象。
$(this)[0] == this
$() 是 jQuery 的构造函数。
这是对调用的 DOM 元素的引用。
所以基本上,在 $(this) 中,你只是将 this 作为参数传递给 $(),以便你可以调用 jQuery 方法和函数。