jquery中this和$(this)区别,我是这样理解的
写过这样一段jq
$('ul li.navbox').hover(function(){
$('div',$(this)).fadeIn('fast'); // 先忽略掉‘div’看,$($(this))也是jq对象
},function(){
$('div',$(this)).fadeOut('fast');
});
$('div',$(this)).fadeIn('fast'); // 先忽略掉‘div’看,$($(this))也是jq对象
},function(){
$('div',$(this)).fadeOut('fast');
});
对比看这样写效果是一样的
$('ul li.navbox').hover(function(){
$('div',this).fadeIn('fast'); //看上去有点儿别扭吧,先忽略掉‘div’,不就是常见的$(this)jq当前对象
},function(){
$('div',this).fadeOut('fast');
});
$('div',this).fadeIn('fast'); //看上去有点儿别扭吧,先忽略掉‘div’,不就是常见的$(this)jq当前对象
},function(){
$('div',this).fadeOut('fast');
});
总结this是js对象,而这里面都是jq对象,他们是$($(this)),和$(this)
单独分析下:
a = this; //a是JS对象
b = $(this); //b是JQ对象
$(a) 和 $(b) ,现在加上了$(),所以他们都是JQ对象了