Q:getelementsbyclassname () in IE browser but normal use, display Web page script error.
A: In the JS file to add the following processing code, it can be a perfect solution to this problem.
//solve the problem that IE cannot use the Getelementsbyclassname () method//if the browser cannot use document. getelementsbyclassname () if(!document.getelementsbyclassname) {//then give the following value to the GCDocument.getelementsbyclassname =function(ClassName, Element) {//Take out all the elements in a file or document varChildren = (Element | | document). getElementsByTagName (' * ');//Create a new array varelements =NewArray ();//iterate through all the elements for(vari=0; i<children.length; i++){//assign the element to child for easy access to classname varChild =Children[i];//Considering that the element has multiple classname varClassnames = Child.className.split ("); for(varj=0; j<classnames.length; J + +){//If the classname is the same as to be taken, then put in a new array if(Classnames[j] = =className) {Elements.push (child); Break; } } } returnelements; }; }
Use of the Getelementsbyclassname () property under IE browser