时间:2020-12-30 14:15:43 | 栏目:jquery | 点击:次
1.HTML代码
<div name="students" school="HK"> <input type="boy" name="ZhangSan" value="206"> <input type="girl" name="Lisi" value="108"> </div>
2.jquery
<script type="text/javascript"> /* find() 查找子元素方法 */ var aaa = $("div[name='students'][school='HK']").find("input[type='boy'][name='ZhangSan']"); console.log(aaa.val()); /* $(".child",parent); 方法查找子元素*/ var bbb = $($("input[type='boy'][name='ZhangSan']"),$("div[name='students'][school='HK']")); console.log(aaa.val()); /* each()方法遍历数组 */ var arr = [ "one", "two", "three", "four" ]; $.each(arr, function() { console.log(this); }); /* each()方法处理json */ var obj = { one : 1, two : 2, three : 3, four : 4 }; $.each(obj, function(key, val) { console.log(obj[key]); }); /* each()方法处理二维数组 */ var arr1 = [ [ 11, 44, 33 ], [ 4, 6, 6 ], [ 7, 20, 9 ] ] $.each(arr1, function(i, item) { console.log(item[0]); }); /* each()方法处理HTML元素 */ $("div[name='students'][school='HK'] > input").each(function() { console.log($(this).val()); }); </script>