JavaScript 获取HTML中的CSS样式的属性以及值的的方法。

 1 <body>
 2 <div id="wow" style="font-size:10px; float:left"></div>
 3 
 4 
 5 
 6 <script type="text/javascript">
 7 
 8 var tempDiv=document.getElementById("wow");
 9 var prop_,value,i,len;
10 
11 alert(tempDiv.style.length);
12 
13 //defined the tempDiv's length;
14 for(i=0,len=tempDiv.style.length;i<len;i++)
15 {
16     //the style arrary of tempDiv;
17     prop_=tempDiv.style[i];
18     
19     //Prop_'s propertyValue;
20     value=tempDiv.style.getPropertyValue(prop_);
21     
22     //Prop_'s propertyCSS-Value;
23     _value=tempDiv.style.getPropertyCSSValue(prop_);
24     
25     //alert(prop_+"=>"+value);
26     
27     //alert the properties accrording to the attributes of the _value object.
28     alert(prop_+"=>"+_value.cssText+":"+_value.cssValueType);
29     
30 }
31 
32 
33 </script>
34 
35 
36 
37 
38 
39 
40 
41 </body>

PS:注释是我写的,因为我一般习惯写英文注释了,不太喜欢写中文参杂在代码里。

代码已经贴出来了,

里面有2个方法:

1.getPropertyValue()

2.getPropertyCSSValue();

这2个方法里的属性大家可以对比一下。

其中getPropertyCSSValue()中的属性:cssValueType是一个存放常量的枚举类型:

Alert出的结果:0(继承的值) 1(基本的值) 2(自定义的值)

 

 

posted @ 2013-11-13 14:56  yangliwen  阅读(2742)  评论(0编辑  收藏  举报
document.getElementById("homeTopTitle").innerText="ღKawaii";