天天饱

如果你只做自己能力范围之内的事情,就永远没法进步

JS动态生成<style>

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

  

posted @ 2016-12-13 03:00  天天饱  阅读(270)  评论(0编辑  收藏  举报