// 深度遍历
function interator(node) {
console.log(node);
if (node.children.length) {
for (var i = 0; i < node.children.length; i++) {
interator(node.children[i]);
}
}
}
// 广度遍历
function interator(node) {
var arr = [];
arr.push(node);
while (arr.length > 0) {
node = arr.shift();
console.log(node);
if (node.children.length) {
for (var i = 0; i < node.children.length; i++) {
arr.push(node.children[i]);
}
}
}
}
js深度、广度 遍历 dom树
最新推荐文章于 2024-07-19 18:30:25 发布