getPropertyValue

来源:互联网 发布:js中怎么使用map 编辑:程序博客网 时间:2024/06/07 12:15
DEMO:
content
<!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方法,直接使用键值访问,其实也是可以的。但是,比如这里的的float,如果使用键值访问,则不能直接使用getComputedStyle(element, null).float,而应该是cssFloatstyleFloat,自然需要浏览器判断了,比较折腾!

使用getPropertyValue方法不必可以驼峰书写形式(不支持驼峰写法),例如:style.getPropertyValue("border-top-left-radius");

getComputedStyle方法在伪类元素上的特异功能
原创粉丝点击