时间:2021-07-01 10:21:17 帮助过:58人阅读
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创建多级目录的两种方法
以上就是递归思想获得页面所有标签元素(去重)的详细内容,更多请关注Gxl网其它相关文章!