<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
label{display: inline-block;width:200px;height:40px;border:1px solid #ccc;}
.ob{width:200px;background:#ccc;padding-top:10px;}
.child{width:100px;height:100px;background:red;}
</style>
</head>
<body>
<div class="ob" id="od">
<ul>
<li class="o1">1</li>
<li class="o2">2</li>
<li class="o3">3</li>
<li class="o4">4</li>
</ul>
</div>
<script>
var dom = document.querySelector("#od");
function getCssValue(elem, property){
var result = null;
if(document.defaultView.getComputedStyle){
result = document.defaultView.getComputedStyle(elem).getPropertyValue(property);
}else if(elem.currentStyle){
result = elem.currentStyle[property];
}
return result;
}
console.log(getCssValue(dom,"color"));
</script>
</body>
</html>
原生js获取元素最终计算结果样式代码
最新推荐文章于 2022-12-05 14:42:50 发布