JQuery查找子元素find()和遍历集合each的方法总结
时间: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>
上一篇:50个比较实用jQuery代码段
栏 目:jquery
下一篇:jQuery禁用快捷键例如禁用F5刷新 禁用右键菜单等的简单实现
本文标题:JQuery查找子元素find()和遍历集合each的方法总结
本文地址:http://www.codeinn.net/misctech/38427.html






