Home > Web Front-end > JS Tutorial > body text

Jquery中的$.each获取各种返回类型数据的使用方法_jquery

WBOY
Release: 2016-05-16 16:01:36
Original
1136 people have browsed it
var arr = [ "one", "two", "three", "four"]; 
$.each(arr, function(){ 
alert(this); 
}); 
Copy after login

上面这个each输出的结果分别为:one,two,three,four

var arr = [ "aaa", "bbb", "ccc" ]; 
$.each(arr, function(i,a){ 
alert(i); // i 是循环的序数
alert(a); // a 是值
}); 
var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]] 
$.each(arr1, function(i, item){ 
alert(item[0]); 
}); 
Copy after login

其实arr1为一个二维数组,item相当于取每一个一维数组,
item[0]相对于取每一个一维数组里的第一个值
所以上面这个each输出分别为:1 4 7

var obj = { one:1, two:2, three:3, four:4}; 
$.each(obj, function(key, val) { 
alert(obj[key]);
alert(key); //键
alert(val); //值
}); 
Copy after login

输出结果为:1 2 3 4

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!