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);
posted @ 2008-11-06 18:26  Sam Lin  阅读(4273)  评论(1编辑  收藏  举报