jquery中遍历时如何将当前数组的索引值传入要绑定的click函数中,想用立即执行函数进行传参,但是写了一下会报错,求大神们给个办法$(".swiper-index.swiper-index-item").each(function(i){//如何将i传入click函数中?$(this).on("click",function(){index=i+1;$swiper.css("left",-imgWidth*index);});})
$(".swiper-index.swiper-index-item").each(function(i){//如何将i传入click函数中?$(this).on("click",function(){index=i+1;$swiper.css("left",-imgWidth*index);});})
//如何将i传入click函数中?$(this).on("click",function(){index=i+1;$swiper.css("left",-imgWidth*index);});})
$(this).on("click",function(){index=i+1;$swiper.css("left",-imgWidth*index);});})
index=i+1;$swiper.css("left",-imgWidth*index);});})
$swiper.css("left",-imgWidth*index);});})
});})
})
慕哥6287543
相关分类