function scanTagsByKeywords(node) {
const set = new Set();
const isTargetNode_ = function (tagName) {
return ( ["a", "d"].indexOf(
tagName.charAt(0)
) > -1);
};
const scanTagsByKeywords_ = function (node_) {
let tagName = node_.tagName && node_.tagName.toLocaleLowerCase();
if (tagName&& isTargetNode_(tagName)) {
set.add(tagName);
}
if (node_.childNodes) {
node_.childNodes.forEach((element) => {
scanTagsByKeywords_(element);
});
}
};
scanTagsByKeywords_(node);
return Array.from(set);
}
console.log(scanTagsByKeywords(document.documentElement));
使用 JavaScript 搜索网页上 a 或者 d 标签的集合
最新推荐文章于 2022-08-18 10:47:21 发布
2023

被折叠的 条评论
为什么被折叠?



