zoukankan      html  css  js  c++  java
  • 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(自定义的值)

  • 相关阅读:
    在Magento产品分类页面创建推荐产品
    任意两个时间之间的星期几的次数纵.sql
    SQL 日期格式化处理.sql
    系统应用程序域
    在ubuntu12.04中,apc_cache_find()
    buildertheory.cs
    复杂年月处理.sql
    CurrentAccounts.cs
    CLR和Windows加载器
    应用程序域
  • 原文地址:https://www.cnblogs.com/kmsfan/p/js.html
Copyright © 2011-2022 走看看