var pColor= document.styleSheets[document.styleSheets.length-1];
alert(pColor);
                                                                   
alert(pColor.rules);
再ie中 都是有值的 可是再火狐中下面这个alert(pColor.rules);是没有值的 我使用的是 Ext的 Ext.menu.ColorItem  请教大家 倒是是为啥?

解决方案 »

  1.   

    使用Ext.menu.ColorItem和styleSheets样式有什么关系啊
      

  2.   

    没关系 我只是说明下的。。  最主要的是 为啥  我这边alert(pColor.rules);是没有值的。
      

  3.   

    rules 和 cssRules 的计数方法也是不一样的!rules 是第几个选择器;cssRules 是第几条规则。 <style type="text/css">  
    a,div,p {color:red}  
    h5 {color:blue}  
    </style>  
    <script>  
    if(document.styleSheets[0].cssRules){  
    alert(document.styleSheets[0].cssRules[1].selectorText+":"+document.styleSheets[0].cssRules[1].style.cssText)  
    }else{  
    alert(document.styleSheets[0].rules[1].selectorText+":"+document.styleSheets[0].rules[1].style.cssText)  
    }  
    </script> 
      

  4.   


     new Ext.Button({
                                                    text:'选择颜色',
                                                    id:'SketchLineColor',
                                                    cls: 'sketchContentName2',
                                                    width:90,
                                                    menu: {
                                                            items: [
                                                                    new Ext.menu.ColorItem({listeners:{"click":function(baseitem, evt){
                                                                        var color=baseitem.component.value;
                                                                        var pColor= document.styleSheets[document.styleSheets.length-1];
                                                                       alert(pColor);
                                                                       alert(pColor.rules);
                                                                        if(pColor.rules[pColor.rules.length-1].selectorText == ".SketchLineColorlab")
                            pColor.removeRule(pColor.rules.length-1);
                                                                        pColor.addRule('.SketchLineColorlab','background-color:'+ '#' + color +'');
                                                                        Ext.getCmp("SketchLineColorlab").render(); 
                                                                    }},scope:this}), '-'
                                                                    //{text:'More Colors...'}
                                                                   ]
                                                          }
                                         })
    我觉得 应该是 rules 第几个选择器 可是 上面这段为啥 再ie中可以。。再火狐中不行呢?
      

  5.   

    SketchLineColorlab  是 要赋色的 label
      

  6.   

    rules      在ie中
    cssRules 在firefox中
    4楼都已经写了。
      

  7.   

    我 测试 过了 使用cssRules   还是 无法 选择颜色 再赋给指定id的label颜色
      

  8.   


     items: [
                                                                    new Ext.menu.ColorItem({listeners:{"click":function(baseitem, evt){
                                                                        var color=baseitem.component.value;
                                                                        var pColor= document.styleSheets[document.styleSheets.length-1];
                                                                    
                                                                        if(pColor.cssRules[pColor.cssRules.length-1].selectorText == ".SketchLineColorlab")
                            pColor.removeRule(pColor.cssRules.length-1);
                                                                        pColor.addRules('.SketchLineColorlab','background-color:'+ '#' + color +'');
                                                                        Ext.getCmp("SketchLineColorlab").render(); 
                                                                    }},scope:this}), '-'
                                                                    //{text:'More Colors...'}
                                                                   ]
    报  是报这句错误 pColor.addRules()没这个方法。。难度 要改成  pColor.addcssRules
      

  9.   

    我始终不明白 这一段的 目的是什么?
     if(pColor.cssRules[pColor.cssRules.length-1].selectorText == ".SketchLineColorlab")
                                                                            pColor.removeRule(pColor.cssRules.length-1);大家 给点 解释啊?
      

  10.   

    在这个样式表中删除.SketchLineColorlab
      

  11.   

    我代码 也贴了 你可以告诉我  为啥 我这边 火狐 无法给 label赋色呢?