首页 > 代码库 > ie7,IE8不支持document.getElmentsByClassName的问题

ie7,IE8不支持document.getElmentsByClassName的问题

 1 if (!document.getElementsByClassName) {
 2     document.getElementsByClassName = function(className, element) {
 3         var children = (element || document).getElementsByTagName(‘*‘);
 4         var elements = new Array();
 5         for (var i = 0; i < children.length; i++) {
 6             var child = children[i];
 7             var classNames = child.className.split(‘ ‘);
 8             for (var j = 0; j < classNames.length; j++) {
 9                 if (classNames[j] == className) {
10                     elements.push(child);
11                     break;
12                 }
13             }
14         }
15         return elements;
16     };
17 }

解决ie7,IE8不支持document.getElmentsByClassName的问题

ie7,IE8不支持document.getElmentsByClassName的问题