<style>
.aa { color:#f00 }
.bb { font-weight:bold }
</style>  <SCRIPT LANGUAGE="JavaScript">
  <!--  var a = document.styleSheets[0];
for(var i=0;i<a.rules.length;i++){
alert(a.rules[i].selectorText);
}  //-->
  </SCRIPT>

解决方案 »

  1.   

    参考:
    <HTML>
    <HEAD>
    <SCRIPT>
    /** Mozilla兼容MsIE脚本,stylesheet扩展部分。
     * o stylesheet.addRule()
     */
    (function () {
    if (! window.CSSStyleSheet) return;
    function _ss_GET_rules_ () {
    return this.cssRules;
    }
    var _ss = CSSStyleSheet.prototype;
    _ss.addRule = function(sSelector, sRule) {
    this.insertRule(sSelector + "{" + sRule + "}", this.cssRules.length);
    }
    _ss.__defineGetter__("rules", _ss_GET_rules_);
    })();function ruleColor(ruleIndex) {
    alert("The color of rule " + ruleIndex + " is " + document.styleSheets[0].rules.item(ruleIndex).style.color + ".");
    }
    </SCRIPT>
    <STYLE>
    .rule0 {color:red;}
    .rule1 {color:blue;}
    </STYLE>
    </HEAD>
    <BODY>
    <P class="rule0" id="oRule0Span">
    Rule 0 is applied to this line.
    </P>
    <P class="rule1" id="oRule1Span">
    Rule 1 is applied to this line.
    </P>
    <BUTTON onclick="ruleColor(0)">Color of Rule 0</BUTTON>
    <BUTTON onclick="ruleColor(1)">Color of Rule 1</BUTTON>
    </BODY>
    </HTML>
      

  2.   

    获取名字:
    alert("The color of rule " + ruleIndex + " is " + document.styleSheets[0].rules.item(ruleIndex).style.color + ".");-->alert("The name of rule " + ruleIndex + " is " + document.styleSheets[0].rules.item(ruleIndex).selectorText + ".");
      

  3.   

    谢谢楼上的同志们
    请问有兼容性更好点的吗?opera不支持 ;(
      

  4.   

    偶的可以支持IE、FF
    opera没环境 ^_^
      

  5.   

    蹭分^o^
    <script type="text/javascript">
    var getStyle = function () {
    var style = document.getElementsByTagName("style")[0];
    var sp = /(^|\s)(.+)\s\{[^}]*\};*/g, ar = new Array();
    while (sp.exec(style.innerHTML))
    Array.prototype.push.apply(ar, RegExp.$2.split(/[ ]*,[ ]*/));
    return ar;
    };
    alert(getStyle().join("\n"));
    </script>
      

  6.   

    <style type="text/css">
    .aa { color:#f00 }
    .bb { font-weight:bold }
    #wc { color:#000000
    }
    #my, aa, bb cc,w:cs { color:#000000}
    </style>
    css忘记贴了。。
      

  7.   

    var sp = /\s*(.+?)\s*\{[^}]*\};*/g, ar = new Array();
    在修改下式子...
      

  8.   

    2楼的还是不兼容...提示找不到style...