Tag: cti Script lang div specifies utf-8 javascrip type stop
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <Scriptsrc= "Https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></Script>6 <Scripttype= "Text/javascript">7 $(function(){8 $.each ([1,2,3],function(index,value) {9 Alert (Index+"=="+value);Ten }) One }) A </Script> - </Head> - the <Body> - - </Body> - </HTML>
The jquery each () function iterates through the specified object and array.
Grammar
$.each (Object,callback)
Traversing objects
1<script type= "Text/javascript" >2$(function(){3 varobj = {4"Site": "You and I he study it",5"Author": "Zhang Xuiliang"6 }7$.each (obj,function(key,value) {8Alert (key + "= =" +value);9 })Ten }) One</script>
Iterating through an array
1<! DOCTYPE html>234<meta charset= "Utf-8" >5<script src= "Https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js" ></script>6<script type= "Text/javascript" >7$(function(){8 vararr = ["One", "one", "one", "three", "four", "five"];9 varobj = {One:1,two:2,three:3,four:4,five:5};Ten$.each (arr,function(i,val) { One$ ("#" +val). Text ("My Is" +val+ ".")); A //stop running after three - //return (Val!== "three"); - }); the$.each (obj,function(i,val) { -$ ("#" +i). Append (document.createTextNode ("-" +val)); - }) - }) +</script> - + A<body> at<div id= "One" ></div> -<div id= "both" ></div> -<div id= "three" ></div> -<div id= "Four" ></div> -<div id= "Five" ></div> -</body> inTraversing an element
1 <script type= "Text/javascript" >2 $ (function() {3 var obj = {name: "John", Lang: "Java"}; 4 5 $.each (obj,function(key,value) {6 alert ("Keyword:" +key+ "= = value:" + value); 7 })8 })9 </script>
"Learn to light it" jQuery each () function usage instance