<style>
#div1{
width: 100px;
height: 1000px;
background: red;
}
</style>
<script>
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
window.onload=function(){
var oDiv=document.getElementById("div1");
alert(getStyle(oDiv,‘width‘))
alert(getStyle(oDiv,‘height‘))
alert(getStyle(oDiv,‘backgroundColor‘))
}
</script>
</head>
<body>
<div id="div1" ></div>
</body>
</html>
时间: 2024-10-17 03:18:44