<pre name="code" class="html"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 200px;
height:100px;
background-color: green;
position: absolute;
left:200px;
top:100px;
}
</style>
</head>
<body>
<div id="dv"></div>
<script src="common.js"></script>
<script>
//封装获取元素计算后的属性值:两个参数,一个元素,一个该元素的属性值
function getAttrValue(element,attr){
return element.currentStyle?element.currentStyle[attr]:window.getComputedStyle(element,null)[attr]||0;
}
console.log(getAttrValue(my$("dv"), "left"));
</script>
</body>
</html>