码迷,mamicode.com
首页 > Web开发 > 详细

getPropertyValue 获取CSS样式

时间:2017-10-26 15:17:24      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   red   一个   函数   调用   ant   doc   div   alert   

新学习一个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>

getPropertyValue 获取CSS样式

标签:style   red   一个   函数   调用   ant   doc   div   alert   

原文地址:http://www.cnblogs.com/yiyi17/p/7736485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!