<script type="text/javascript"> 
(function () { 
    if (window.CSSStyleSheet) { 
        var wc = window.CSSStyleSheet.prototype; 
        wc.addRule = function (a, b) { 
            var wc = this; 
            wc.insertRule(a + "{" + b + "}", wc.cssRules.length); 
        }; 
        wc.removeRule = function (a) { 
            var wc = this; 
            wc.deleteRule(a); 
        }; 
        wc.__defineGetter__("rules", new Function("return this.cssRules")); 
    } 
})(); var addRule = function (a, b) { 
    var wc = document.styleSheets[0], i; 
    for (i = 0 ; i < wc.rules.length ; i ++) if (wc.rules[i].selectorText == a) wc.removeRule(i); 
    wc.addRule(a, b); 
}; 
var add = function () { 
    var wc = document.getElementById("wc").value; 
    if (/([^\{]+)\s*(\{[^}]+\})/.test(wc)) { 
        addRule(RegExp.$1, RegExp.$2); 
    } else { 
        alert("样式错误"); 
    } 
}; 
</script> 我的问题就是想问在window.CSSStyleSheet中这个CSSStyleSheet属性是什么?还有就是document.styleSheets[0]中的styleSheets属性数组又是表示什么?感觉JS中有很多类似对象的属性都很莫名奇妙,而且我查手册也查不到

解决方案 »

  1.   

    这是wc的代码..
    CSSStyleSheet是自定义的全局对象..
    document.styleSheets[0] 是指代CSS样式表的第一个样式
      

  2.   

    IE6没这个CSSStyleSheet属性.那个是FF的
    styleSheets才是IE的.
    你查手册肯定能查到的.注:手册是IE的.
      

  3.   

    CSSStyleSheet对象可参考
    JavaScriptDOM高级程序设计 
    Document.styleSheet
    一组关联于文档的样式表片段集合.
    参考
      

  4.   

    参考这里:
    http://seahorsedad.blog.hexun.com/33236162_d.html 
      

  5.   

    这是ie的DOM/CSS对象, 不是查js手册,要查DOM.CSSCSSStyleSheet
    http://msdn.microsoft.com/en-us/library/dd347054(VS.85).aspxstyleSheets
    http://msdn.microsoft.com/en-us/library/ms531200(VS.85).aspx
      

  6.   

    document.styleSheets是所有引入的样式表集合,包括<link>和<style>
    window.CSSStyleSheet通同styleSheets
      

  7.   

    是不是这个意思
    if (window.CSSStyleSheet)这一部分的代码段是针对FF浏览器的?
    下面才是针对IE浏览器的?
      

  8.   

    差不多吧.不过IE8开始就支持window.CSSStyleSheet了.参见上面HOOKEE的链接.
    所以应该是判断浏览器支持window.CSSStyleSheet不.