<style>
.w80{width:80px; height:20px}
</style>
function getc(){
var ec=document.styleSheets[0];
var ew=ec.rules[0];
alert(ew.style.width);//80px
}

解决方案 »

  1.   

    class中的值无法用style获得的,楼上的可以,还可以用document.styleSheets来得到样式表
      

  2.   

    var ec=document.styleSheets[0];使用这个方法,还要确定styleSheets[X]的位置,是不是很麻烦?
    如果这样的Css,各种样式的上下行可能会变,是不是就限制了这种方法的使用?<style>
             .w8{width:8px; height:20px}
    .w80{width:80px; height:20px}
             .w800{width:800px; height:20px}
    </style>
      

  3.   

    还有一点,使用Dom结构制造的接点好象支持 e.style.width='100';
    这样的设置,为什么?比如
    var e=document.createElement('div');
    e.style.width='100';
    e.style.color='red';这个是可以设定的。原因呢
      

  4.   

    currentStyle
    --------------------<style>
    .w80{width:80px;}
    </style>
    <div class="w80" id="m">AAA</div>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var e=document.getElementById('m');
    alert(e.currentStyle.width); 
    //-->
    </SCRIPT>
      

  5.   

    alert(e.currentStyle.width);  ???
    如果这样呢<style>
    .w80{width:80px;}
    .h40{height:40px;}
    </style>
    <div class="w80 h40" id="m">AAA</div>currentStyle取的是w80还是h40?,还是他们的并集
      

  6.   

    currentStyle是元素实际表现出来的CSS属性
    <style>
    .w80{width:80px;}
    .h40{height:40px;}
    </style>
    <div class="w80 h40" id="m">AAA</div>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var e=document.getElementById('m');
    alert(e.currentStyle.width); 
    //-->
    </SCRIPT>
      

  7.   

    或者这样更明显些
    <style>
    .w80{width:80px!important;height:80px;}
    .h40{width:40px;height:40px;}
    </style>
    <div class="w80 h40" id="m" style="border:solid 1px #6396C9">AAA</div>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var e=document.getElementById('m');
    alert(e.currentStyle.width); 
    //-->
    </SCRIPT>