本文主要为大家带来一篇jquery查找子元素find()和遍历集合each的方法总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望让大家更好掌握find()和遍历集合each的使用方法。
1.HTML代码
<p name="students" school="HK"> <input type="boy" name="ZhangSan" value="206"> <input type="girl" name="Lisi" value="108"> </p>
2.jquery
<script type="text/javascript">
/* find() 查找子元素方法 */
var aaa = $("p[name='students'][school='HK']").find("input[type='boy'][name='ZhangSan']");
console.log(aaa.val());
/* $(".child",parent); 方法查找子元素*/
var bbb = $($("input[type='boy'][name='ZhangSan']"),$("p[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元素 */
$("p[name='students'][school='HK'] > input").each(function() {
console.log($(this).val());
});
</script>相关推荐:
jQuery中find()和filter()操作用法实例详解
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
jQuery中focusin()与focus()以及find()于children()的区别
以上就是JQuery查找子元素find()和遍历集合each的方法实例分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号