Last active
August 4, 2017 12:31
-
-
Save mercer08/07d479f2d1d0dc85d4789d4c7f1845d5 to your computer and use it in GitHub Desktop.
this is code of the book(DOM Scripting Web Design with JavaScript and the Doucment Object Model), the way to make the method of getElementByClassName to be true;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getElementByClassName (node,classname) { | |
if (node.getElementByClassName) { | |
return node.getElementByClassName(classname); | |
} else { | |
var elems = getElementByTagName("*"); | |
var results = []; | |
for (var i = 0; i < elems.length; i++) { | |
if (elems[i].className.indexOf(classname) != -1) { | |
results.push(elems[i]); | |
} | |
} | |
return results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
即使是这样一段简单的代码,我也错了三个地方;
妈的,智障.