jQuery中的遍历方法each的使用
each有三种遍历方法,使用的时候需要结合实际情况使用。
1.基础使用
$('div').each(function (i){this.()。。});
i就是索引值,this 就是指当前的dom对象。
2.选择器+遍历的使用
$('div').each(function (index,domex){
index就是索引值
domex 表示获取遍历每一个dom对象
});
3.使用更多的遍历
1.先获取集合对象
var ex=$("div");
2.遍历元素
$.each(ex,function (index,domex){
ex是要遍历的集合
index就是索引值
domex 表示获取遍历每一个dom对
});