- var CSS = ‘h1 { background: red; }’,
- head = document.getElementsByTagName(‘head’)[0],
- style = document.createElement(’style’);
- style.type = ‘text/css’;
- if(style.styleSheet){
- style.styleSheet.cssText = css;
- }else{
- style.appendChild(document.createTextNode(css));
- }
- head.appendChild(style);
- //该片段来自于http://www.codesnippet.cn/detail/171020136462.html
来源: http://www.codesnippet.cn/detail/171020136462.html