var walk_the_DOM = function walk(node, func){
func(node);
node = node.firstChild;
while (node) {
walk(node,func);
node = node.nextSibling;
}
};
var getElementsByAttribute = function (att, value) {
var results = [];
walk_the_DOM(document.body,function (node) {
var actual = node.nodeType === 1 && node.getAttribute(att);
if (typeof actual === "string" && (actual === value || typeof value !== "string")) {
results.push(node);
}
});
return results;
};
主要是if (typeof actual === "string" && (actual === value || typeof value !== "string"))这一句

圈住的那一部分
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个“actual ” 是上句获取到的属性值;进而来和value 来做对比;当值一样是也就是
这个条件成立;证明这个是要找的值,这个是找到属性和属性值一样的元素;
这个条件成立时;是找到含有这个属性;但属性值不相同的元素;(从字面上理解)
总结:就是这个通过属性获取元素的方法,必须需要一个属性,属性值非必须;
条件语句 意思就是 前一段 typeof actual === "string" :=> actual的类型是字符串类型
后面花括号里面 (actual === value || typeof value !== "string") actual严格相等value或者value的类型不是 字符串类型
我不知道 是不是你要的答案