首页 > 代码库 > 关于IE8 、IE7不支持getElementsByClassName的结局方案

关于IE8 、IE7不支持getElementsByClassName的结局方案

复制此代码到<header></header>

<!--[if IE 8]>
  <script type="text/javascript">

    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;
      };
    }

  </script>

<![endif]-->

 

关于IE8 、IE7不支持getElementsByClassName的结局方案