JavaScript添加style节点
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);