jQuery $.each()常见的几种使用方法
<code class="language-html"><!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link href="../css/mui.min.css" rel="stylesheet" /> </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" /> <script src="../js/mui.min.js"></script> <script type="text/javascript" src="../js/jquery.js"></script> <script type="text/javascript"> mui.init() //处理一维数组 var arr1 = ["aaa", "bbb", "ccc"]; $.each(arr1, function(i, val) { console.log(i + val); }); //处理二维数组 var arr2 = [ ['a', 'aa', 'aaa'], ['b', 'bb', 'bbb'], ['c', 'cc', 'ccc'] ]; $.each(arr2, function(i, item) { console.log(i + "====" + item); $.each(item, function(j, val) { console.log(j + "====" + val) }); }); //处理json数据 var obj = { one: 1, two: 2, three: 3 }; $.each(obj, function(key, val) { console.log(key + "===" + val) }) //处理dom元素 $.each($("input:hidden"), function(i, val) { console.log("i===" + i) console.log(val.name) console.log(val.value) }) </script> </body> </html></code>
posted on 2018-09-29 09:35 Steven5007 阅读(342) 评论(0) 编辑 收藏 举报