The native JS method "Document.getelementsbyclassname" cannot be used in IE8 and the following browsers.
Modify: Add compatibility judgment and modify the Getclassnames method to the location where the method needs to be used.
The code is as follows:
Original method: Document.getelementsbyclassname (' Tabs_div ');
Here the method is called: Getclassnames (' tabs_div ', ' div ');
var divs = getclassnames (' tabs_div ', ' div ');
function Getclassnames (classstr,tagname) {
if (document.getelementsbyclassname) {
Return Document.getelementsbyclassname (CLASSSTR)
}else {
var nodes = document.getElementsByTagName (tagName), ret = [];
for (i = 0; i < nodes.length; i++) {
if (Hasclass (NODES[I],CLASSSTR)) {
Ret.push (Nodes[i])
}
}
return ret;
}
}
function Hasclass (TAGSTR,CLASSSTR) {
var arr=tagstr.classname.split (/\s+/); This regular expression is because class can have more than one, judging whether it contains
for (Var i=0;i<arr.length;i++) {
if (ARR[I]==CLASSSTR) {
return true;
}
}
return false;
}
Native JS method Document.getelementsbyclassname in IE8 and the following compatibility issues