// 实例化 TreeWalker 对象 let walker = document.createTreeWalker( document.documentElement, NodeFilter.SHOW_ELEMENT ); // 遍历 let node = walker.nextNode(); while (node !== null) { node.style.outline = "1px solid #" + (~~(Math.random() * (1 << 24))).toString(16); node = walker.nextNode(); }