(1)$(selector).each(),遍历函数,选中的标签中的每一个执行function(I,element),i,是其中标签的索引(0~selector.length-1).用于对象,element是指当前对象。
(2)$.each(); 是对数组以及对象集合操作。
如果是数组:var array1 = [‘one’ , ‘two’ , ‘three’ , ‘fore’]
$.each(array1,function(index,value){
Alert(index + “ :” + value) //index 是索引,value是值
});
结果:0 :one
1 : two
2: three
3 : fore
如果是对象集合: var array2 = [‘name’:’kk ‘, ‘age’:’11’;]
$.each(array2,function(index,value){
Alert(index + “ :” + value) //index 是索引,也是name,value是值
});
结果: name : kk
Age : 11
二维数组:
var arr1 = [ “one”, “two”, “three”, “four”, “five” ];
$.each(arr1, function(){
alert(this);
});
输出:one two three four five
var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each(arr2, function(i, item){ // I 是索引 value 是每一个一维数组
alert(item[0]);
});
输出:1 4 7
未经允许不得转载:博客 » jQuery-each()
评论前必须登录!
登陆 注册