js代碼部分:<script>//前臺(tái)調(diào)用var $=function(){ return new Base();}; //避免了一些bug//基礎(chǔ)庫function Base(){ //創(chuàng)建一個(gè)數(shù)組,來保存節(jié)點(diǎn) 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經(jīng)調(diào)試正確 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>
IE11不支持addRule了嗎???
typhoontaifeng
2016-04-20 10:12:54