var oDiv = document.getElementsByClassName('demo')[0]
function getStyle(ele,name){
if(window.getComputedStyle){
return getComputedStyle(ele,null)[name]
}else{
return ele.getCurrentStyle[name]
}
}
console.log(getStyle(oDiv,'width'))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>封装getStyle方法</title>
</head>
<body>
<div class="demo">demo</div>
</body>
</html>
.demo{
width:200px;
height: 200px;
background: #f40;
}