放飞自我 LET DREAMS FLY

js在head里插入style样式

代码如下:

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); 

 

posted on 2016-06-06 10:39  niuben  阅读(3442)  评论(0编辑  收藏  举报

导航