1. 程式人生 > >jquery中each的3種遍歷方法

jquery中each的3種遍歷方法

每一個 dom對象 cti 遍歷集合 class 集合 div this 一個

1、選擇器+遍歷

$(‘div‘).each(function (i){

i就是索引值

this 表示獲取遍歷每一個dom對象

});

2、選擇器+遍歷

$(‘div‘).each(function (index,domEle){

index就是索引值

domEle 表示獲取遍歷每一個dom對象

});

3、更適用的遍歷方法

1)先獲取某個集合對象

2)遍歷集合對象的每一個元素

var d=$("div");

$.each(d,function (index,domEle){

d是要遍歷的集合

index就是索引值

domEle 表示獲取遍歷每一個dom對

});

jquery中each的3種遍歷方法