IE 8 and 7 bug when dynamically adding a stylesheet

后端 未结 1 1094
别那么骄傲
别那么骄傲 2020-12-19 07:36

I have the following code

var style = document.createElement(\'style\');
style.setAttribute(\"type\", \"text/css\");
if (style.textContent) { // FF, Safari
          


        
相关标签:
1条回答
  • 2020-12-19 08:21

    you can try this way

    var style = document.createElement('style');
    var text = this.arg.css;
    style.setAttribute("type", "text/css");
    if (style.styleSheet) {   // for IE
        style.styleSheet.cssText = text;
    } else {                // others
        var textnode = document.createTextNode(text);
        style.appendChild(textnode);
    }
    var h = document.getElementsByTagName('head')[0];
    h.appendChild(style);
    
    0 讨论(0)
提交回复
热议问题