js代码部分:
<script>
//前台调用
var $=function(){
return new Base();
}; //避免了一些bug
//基础库
function Base(){
//创建一个数组,来保存节点
this.elements=[];
}
Base.prototype.addRule=function(num,selectorText,cssText,position){
var styleSheet=document.styleSheets[num];
if((typeof styleSheet.addRule)!='undefined'){ //IE有问题
styleSheet.addRule(selectorText,cssText,position);
}else if((typeof sheet.insertRule)!='undefined'){ //w3c经调试正确
styleSheet.insertRule(selectorText+'{'+cssText+'}',position);
}
};
window.onload=function(){
//添加和删除link或style样式
$().addRule(0,'body','background:green',0);
};
</script>
===================================================
html部分代码:
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>...</title>
<link rel="stylesheet" type="text/css" href="demo.css"/>
<script type="text/javascript" src="demo.js"></script>
<script type="text/javascript" src="base.js"></script>
</head>
<body>
</body>
</html>
typhoontaifeng