如题,目前只对IE,FireFox,Opera这三种浏览器的兼容性进行过测试,其它浏览器还未测试。
有兴趣的朋友可以研究一下,应该也没问题的。
function AttachStyle(styDom, styCss, styId){
var istyle = styDom.createElement('style');
istyle.setAttribute("type", "text/css");
if(styId!=null){if(!document.getElementById(styId)){istyle.setAttribute("id", styId);}}
if (istyle.styleSheet){
istyle.styleSheet.cssText=styCss;
}else{
istyle.appendChild(styDom.createTextNode(styCss));
}
styDom.getElementsByTagName("head")[0].appendChild(istyle);
}
应用代码:
if(!document.getElementById('attach-css-1')){
var iCss='';
iCss+='.test-style1 {font-size:18px;color:#f60;}';
iCss+='.test-style2 {font-size:16px;color:#f60;}';
iCss+='.test-style3 {font-size:14px;color:#f60;}';
iCss+='.test-style4 {font-size:12px;color:#f60;}';
AttachStyle(document,iCss,'attach-css-1');
}
/**
大家可以测试一下 test-style1,test-style2,test-style3 这三个样式变化了吗?
**/
该页面还没有任何评论,赶快占个沙发吧!