jQuery中的$(this)和this有什么区别? [英] What's the difference between $(this) and this in jQuery?
本文介绍了jQuery中的$(this)和this有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery中的$(this)
和this
有什么区别,为什么它们有时会给出相同的结果而其他时候却表现不同?
What's the difference between $(this)
and this
in jQuery, and why do they sometimes give the same result and other times behave differently?
推荐答案
$(this)
使用jQuery功能包装this
.
$(this)
wraps this
with the jQuery functionality.
例如,此代码将失败:
$('.someDiv').onClick(function(){
// this refers to the DOM element so the following line would fail
this.fadeOut(100);
});
因此,我们将this
包装在jQuery中:
So we wrap this
in jQuery:
$('.someDiv').onClick(function(){
// wrap this in jQuery so we can use jQuery fadeOut
$(this).fadeOut(100);
});
这篇关于jQuery中的$(this)和this有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文