ie8 不支持 document.getElementsByClassName

在使用  document.getElementsByClassName 前加上

  

   if (!document.getElementsByClassName) {
                document.getElementsByClassName = function (className, element) {
                    var children = (element || document).getElementsByTagName('*');
                    var elements = new Array();
                    for (var i = 0; i < children.length; i++) {
                        var child = children[i];
                        var classNames = child.className.split(' ');
                        for (var j = 0; j < classNames.length; j++) {
                            if (classNames[j] == className) {
                                elements.push(child);
                                break;
                            }
                        }
                    }
                    return elements;
                };
            }
 
ok!
posted @ 2020-03-26 13:45  J__F  阅读(149)  评论(0编辑  收藏  举报