您的位置:首页 > Web前端 > JavaScript

利用js动态创建 <style>

2013-12-30 14:01 441 查看
实例:

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://webchina110.cn/?p=328
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: