JQuery查找子元素find()和遍历集合each的方法总结
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>
相关推荐
lylicai 2018-02-07
89423661 2011-11-18
pplxh 2016-01-04
83473469 2018-09-12
ParadiserD 2018-09-12
pplxh 2016-03-30
聆听蘭 2016-01-04
pplxh 2014-04-15
原為簡單 2013-11-06
82483564 2012-12-05
JeWangZhe 2012-11-17
LingPF 2019-06-21
88284453 2011-11-24
gxr 2018-07-16