feng_013

 

(function() {
      var isLoaded = false;
      AddStyle = function(rules) {
        var styleElement = document.createElement(\'style\');
        styleElement.type = \'text/css\';
        if ( $IE ) {   //判断IE浏览器
          styleElement.styleSheet.cssText = rules;
        }
        else {
          var frag = document.createDocumentFragment();
          frag.appendChild(document.createTextNode(rules));
          styleElement.appendChild(frag);
        }
        function append() {
          document.getElementsByTagName(\'head\')[0].appendChild(styleElement);
        }
		//IE 无法取到document
        if (!$IE || isLoaded) { 
          append();
        }
        else {
          window.attachEvent(\'onload\', function() {
            isLoaded = true;
            append();
          });
        }
      };
	  })();

 

 

用法:

 

AddStyle(\'body { color: #CCC; }\')

分类:

技术点:

相关文章:

  • 2021-08-02
  • 2021-12-19
  • 2021-12-05
  • 2021-12-16
  • 2021-12-05
  • 2021-12-23
  • 2021-12-30
猜你喜欢
  • 2021-12-15
  • 2021-12-05
  • 2019-08-14
  • 2021-11-05
  • 2021-11-05
  • 2021-12-05
  • 2021-12-30
相关资源
相似解决方案