可能重复:
使用 JavaScript 获取 CSS 值
你能告诉我为什么我在加载页面时无法获取这些 CSS 属性吗?
javascript:
function aviso(){
alert("top: "+document.getElementById("divRojo").style.top);
alert("position: "+document.getElementById("divRojo").style.position);
}
HTML:
<html>
<head>
<style type="text/css">
#divRojo {
width:100px;
height:100px;
background:red;
left:200px;
top:200px;
position:static;
}
</style>
</head>
<body onload="aviso()">
<div id="divRojo">
Div Rojo
</div>
</body>
</html>
提前致谢