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

jQuery each()小议_jquery

WBOY
Release: 2016-05-16 18:31:57
Original
1157 people have browsed it
Copy code The code is as follows:

var arr1 = [ "one", "two", "three" , "four", "five" ];
$.each(arr1, function(){
alert(this);
});

Output: one two three four five
Copy code The code is as follows:

var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each(arr2, function(i, item){ The name of the parameter can be defined by yourself, and the each method will be based on the first parameter (arr2) format to determine the correctness of the callback function method body syntax
alert(item[0]);
});

Output: 1 4 7
Copy code The code is as follows:

var obj = { one:1, two:2, three:3, four:4, five:5 };
$.each(obj, function(key, val) {
alert(obj[key]);
});

Output: 1 2 3 4 5
Copy code The code is as follows:

$.each( $("input:hidden"), function(){
alert(this.name);
});
$.each($("input:hidden"), function(){
alert(this.value);
});

Bounce traversal
Copy code The code is as follows:

$(document).ready(
function test()
{ var index=0;
var arr1 = [[1, 4, 3 ], [4, 6, 6], [7, 20, 9]]
$.each(arr1, function(i,item){
if(i==1)
{
alert("Click to continue the next traversal");
return ; //return false ; then jump out of the traversal
}
alert('index' i '_' item[0]);
});
})
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!