Regarding the code snippet below:
if (type === '#') {
return doc.getElementById(identifier);
} else if (type === '.' && doc.getElementsByClassName) {
return doc.getElementsByClassName(identifier);
} else if (type === '@') {
return doc.getElementsByName(identifier);
}
It appears not to lik the if / else if all together?
答案 0 :(得分:0)
You have a return
in your if
block, so any else
and else if
blocks following it are unnecessary since they would never be evaluated if the function returned.
Try change the else if
s to just if
s.
答案 1 :(得分:0)
I think that in the else if (type === '.' && doc.getElementsByClassName) {
is missing the class in doc.getElementsByClassName
You should add the class name, i.e.:
doc.getElementsByClassName('className');