function getTheStyle(element, style){
return element.currentStyle? element.currentStyle[style] : window.getComputedStyle(element, null)[style]
}
<style>
#mydiv {
width: 100px; //这里设置了div的宽度,下面要用到
height: 100px;
border: 10px solid yellow;
background: red;
color: green;
margin: 20px;
}
</style>
<div id="mydiv"></div>
<script>
function getTheStyle(element, style){
return element.currentStyle? element.currentStyle[style] : window.getComputedStyle(element, null)[style]
}
console.log(getTheStyle(mydiv, 'width')) //100px
</script>