复制代码 代码如下: var arr1 = [ "one", "two", "three", "four", "five" ]; $.each(arr1, function(){ alert(this); }); 输出:one two three four five 复制代码 代码如下: var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] $.each(arr2, function(i, item){ 参数的名字可以自己定义,each方法会根据第一个参数(arr2)的格式而判断回调函数方法体语法的正确性 alert(item[0]); }); 输出:1 4 7 复制代码 代码如下: var obj = { one:1, two:2, three:3, four:4, five:5 }; $.each(obj, function(key, val) { alert(obj[key]); }); 输出:1 2 3 4 5 复制代码 代码如下: $.each($("input:hidden"), function(){ alert(this.name); }); $.each($("input:hidden"), function(){ alert(this.value); }); 跳出遍历 复制代码 代码如下: $(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("点击继续下次遍历"); return ; //return false ;则跳出遍历 } alert('索引'+i+'_'+item[0]); }); })
推荐阅读
Jquery Ajax学习实例6 向WebService发出请求,返回DataSet(XML) 异步调用
一、WebService.asmx: 处理业务数据,在GetDataSet()方法中产生DataSet(XML)数据,供JqueryRequest.aspx调用,代码如下: 复制代码 代码如下: [WebMethod] public DataSet GetDataSet() { DataSet ds = ne>>>详细阅读
本文标题:jQuery each()小议
地址:http://www.17bianji.com/kaifa2/JS/26819.html
1/2 1