Copy codeThe Code is as follows:
<Html>
<Head>
<Title>
Use jquery each
</Title>
<Script type = 'text/javascript 'src = 'jquery-1.8.2.min.js'> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
// Traverse a one-dimensional array
Var arr1 = ["aaa", "bbb", "ccc"]; // use [] instead of {} for different time-varying values from the C Language {}
$. Each (arr1, function (I, val ){
Alert (I + "subscripts followed by values" + val );
});
// Traverse two-dimensional arrays
Var arr2 = [['A', 'aaa', 'aaa'], ['B', 'bbb', 'bbb'], ['C ', 'cc', 'ccc '];
$. Each (arr2, function (I, item ){
Alert (I + "subscripts followed by values" + item );
});
$. Each (arr2, function (I, item ){
$. Each (item, function (j, val ){
Alert (j + "The subscript is followed by the value" + val );
});
});
// Cyclically traverse the dom object
$. Each ($ ("input: hidden"), function (I, val ){
Alert (val); // It is a dom object.
Alert (I); // subscript 0 1 2
Alert (val. name );
Alert (val. value );
});
// The result is the same as above
$ ("Input: hidden"). each (function (I, val ){
Alert (I );
Alert (val );
Alert (val. name );
Alert (val. value );
});
});
</Script>
</Head>
<Body>
<Input name = "aaa" type = "hidden" value = "111"/>
<Input name = "bbb" type = "hidden" value = "222"/>
<Input name = "ccc" type = "hidden" value = "333"/>
<Input name = "ddd" type = "hidden" value = "444"/>
</Body>
</Html>