<div class="codetitle"> <span><a style="CURSOR: pointer" data="2524" class="copybut" id="copybut2524" onclick="doCopy('code2524')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code2524"> <br><html> <br><head> <br><title> <br>jquery each使用 <br></title> <br><script type='text/javascript' src='jquery-1.8.2.min.js'></script> <br><br><script type="text/javascript"> <br>$(document).ready(function(){ <br>//进行遍历一维数组 <br>var arr1 = [ "aaa", "bbb", "ccc" ]; //同c语言不同时变量值使用[] 而不是{} <br>$.each(arr1, function(i,val){ <br>alert(i "前面是下标后面是值" val); <br>}); <br><br>//遍历二维数组 <br>var arr2 = [['a', 'aa', 'aaa'], ['b', 'bb', 'bbb'], ['c', 'cc', 'ccc']]; <br> $.each(arr2, function(i, item){ <br>alert(i "前面是下标后面是值" item); <br> }); <br> $.each(arr2, function(i, item){ <br> $.each(item,function(j,val){ <br> alert(j "前面是下标后面是值" val); <br> }); <br>}); <br><br>//循环遍历dom对象 <br>$.each($("input:hidden"), function(i,val){ <br>alert(val); //为dom对象 <br>alert(i); //为下标0 1 2 <br>alert(val.name); <br>alert(val.value); <br>}); <br>//结果和上面一样 <br>$("input:hidden").each(function(i,val){ <br>alert(i); <br>alert(val); <br>alert(val.name); <br>alert(val.value); <br>}); <br><br><br>}); <br><br></script> <br></head> <br><body> <br><input name="aaa" type="hidden" value="111" /> <br><input name="bbb" type="hidden" value="222" /> <br><input name="ccc" type="hidden" value="333" /> <br><input name="ddd" type="hidden" value="444"/> <br></body> <br></html> <br> </div>