getPropertyValue 获取CSS样式

新学习一个js 的方法 getPropertyValue   (实现 js框架中  css 的最终调用的函数),取得元素最终计算出的css 样式

 

 

DEMO:

<!DOCTYPE html>

<html>
<head>
    <title></title>
    <meta charset="gbk">
    <style type="text/css">
        #content {
            color: red !important;;
        }
    </style>
</head>
<body>
<div id="content" style="color:yellow">content</div>
</body>


<script type="text/javascript">
    var a = document.getElementById("content");
    alert("style "+a.style.color);
    alert("css "+window.getComputedStyle(a).getPropertyValue("color"));
</script>
</html>

posted @ 2017-10-26 13:59  地铁程序员  阅读(1051)  评论(0编辑  收藏  举报