為什么在each和for循環(huán)中用_this代替$(this)
item.each(function(){
//這里用_this代替$(this)有什么好處么
var _this = $(this);
var itemTop = _this.offset().top;
if(top > itemTop-150){
currentId = "#" + _this.attr('id');
}else{
return false;
}
});
item.each(function(){
//這里用_this代替$(this)有什么好處么
var _this = $(this);
var itemTop = _this.offset().top;
if(top > itemTop-150){
currentId = "#" + _this.attr('id');
}else{
return false;
}
});
2017-10-21
舉報
2017-12-22
_this是一個變量,當(dāng)遍歷items時,將每一個item都存儲在變量里,這樣調(diào)用的時候不需要再去遍歷。
2017-10-22
那個不是代替,就是jQuery必須用$( )這種格式。單存的this只是js里的