jquery学习——遍历

时间:2023-03-09 04:29:12
jquery学习——遍历

1.each()

$(selector).each(function(index,element))

var arr = [ "a", "bb", "ccc" ];
$.each(arr,function(i,a){
console.log(i+":"+a);
});
//直接对jquery对象遍历
$(arr).each(function(i,a){
console.log(i+":"+a);
});

其中,i是遍历对象的遍历顺序,a是当前遍历对象的值,可以用this代替