<div class="codetitle"> <span><a style="CURSOR: pointer" data="52378" class="copybut" id="copybut52378" onclick="doCopy('code52378')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code52378"> <br> <br> <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></script> <br> <br> <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> <br> <br> </div>