Change the content of a

相关标签:
2条回答
  • 2021-02-09 05:49

    Today, in all browsers (including I believe IE9+), you can set the value of textContent on the style element and it will work the way you want, including > in selectors.

    0 讨论(0)
  • 2021-02-09 05:55

    Generating CSS on the fly has its advantages. If you would like to set the innerHTML of a style element in IE use styleSheet.cssText. For example: http://jsbin.com/awecu4

    <!doctype html>
    <script>
    var style = document.createElement('style'),
    script = document.getElementsByTagName('script')[0],
    styles = '#test{background:green;}';
    script.parentNode.insertBefore(style, script);
    
    try{style.innerHTML = styles;}
    //IE fix
    catch(error){style.styleSheet.cssText = styles;}
    </script>
    <div id=test>Div with id of test</div>
    
    0 讨论(0)
提交回复
热议问题