js为元素动态添加css代码

 IE:

 

Code
cssStr = "p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createStyleSheet();
style.cssText
= cssStr;

 

FF:

 

Code
cssStr = "p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createElement("style");
style.type
= "text/css";
style.innerHTML
= cssStr;
win.document.getElementsByTagName(
"HEAD").item(0).appendChild(style);

你可能感兴趣的:(css)