码迷,mamicode.com
首页 > Web开发 > 详细

js在head里插入style样式

时间:2016-06-06 11:49:53      阅读:181      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!