本篇文章给大家分享了用递归思想获得页面所有标签元素的代码,有需要的小伙伴可以参考一下这个代码
var tag = []; var search = function($element, tag){ var localName = $element[0].localName; if(!tag.includes(localName)){ tag.push($element[0].localName); } var children = $element.children(); if(children.length > 0) { children.each(function(e){ search($(this), tag); }); } return tag; }; tag = search($('html'), tag); console.log(tag);
利用递归思想遍历所有元素,最后返回数组
相关推荐:
以上就是递归思想获得页面所有标签元素(去重)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号