首页 > Web开发 > 详细

js在head里插入style样式

时间:2016-06-06 11:47:32      阅读:178      评论:0      收藏:0      [点我收藏+]

代码如下:

1 var nod = document.createElement(‘style‘),   
2     str = ‘body{background:#000;color:#fff} a{color:#fff;text-decoration:none;} a:hover{color:red;text-decoration:underline}‘;  
3     nod.type=‘text/css‘;  
4     if (nod.styleSheet) { //ie下  
5         nod.styleSheet.cssText = str;
6     } else {
7         nod.innerHTML = str; //或者写成 nod.appendChild(document.createTextNode(str))  
8     }
9     document.getElementsByTagName(‘head‘)[0].appendChild(nod); 

 

js在head里插入style样式

原文:http://www.cnblogs.com/niubenbit/p/5562967.html

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