为了账号安全,请及时绑定邮箱和手机立即绑定

为什么在each和for循环中用_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;

}

});


正在回答

2 回答

_this是一个变量,当遍历items时,将每一个item都存储在变量里,这样调用的时候不需要再去遍历。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么在each和for循环中用_this代替$(this)

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信