<style>
.w80{width:80px; height:20px}
</style>
function getc(){
var ec=document.styleSheets[0];
var ew=ec.rules[0];
alert(ew.style.width);//80px
}
.w80{width:80px; height:20px}
</style>
function getc(){
var ec=document.styleSheets[0];
var ew=ec.rules[0];
alert(ew.style.width);//80px
}
如果这样的Css,各种样式的上下行可能会变,是不是就限制了这种方法的使用?<style>
.w8{width:8px; height:20px}
.w80{width:80px; height:20px}
.w800{width:800px; height:20px}
</style>
这样的设置,为什么?比如
var e=document.createElement('div');
e.style.width='100';
e.style.color='red';这个是可以设定的。原因呢
--------------------<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>
如果这样呢<style>
.w80{width:80px;}
.h40{height:40px;}
</style>
<div class="w80 h40" id="m">AAA</div>currentStyle取的是w80还是h40?,还是他们的并集
<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>
<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>