首页 > Web开发 > 详细

JS动态生成<style>

时间:2016-12-13 08:10:07      阅读:251      评论:0      收藏:0      [点我收藏+]
var nod = document.createElement(“style”),   
str = “body{background:#000;color:#fff} a{color:#fff;text-decoration:none;} a:hover{color:red;text-decoration:underline}”;  
nod.type=”text/css”;  
if(nod.styleSheet){         //ie下  
nod.styleSheet.cssText = str;  
} else {  
nod.innerHTML = str;       //或者写成 nod.appendChild(document.createTextNode(str))  
}  
document.getElementsByTagName(“head”)[0].appendChild(nod);  

  

JS动态生成<style>

原文:http://www.cnblogs.com/gxsyj/p/6168425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!