- 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);
来源: http://www.bubuko.com/infodetail-1869983.html