Skip to content

Instantly share code, notes, and snippets.

@mercer08
Last active August 4, 2017 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mercer08/07d479f2d1d0dc85d4789d4c7f1845d5 to your computer and use it in GitHub Desktop.
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;
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;
}
}
@mercer08
Copy link
Author

mercer08 commented May 1, 2016

即使是这样一段简单的代码,我也错了三个地方;
妈的,智障.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment