<head> javascript
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> html
<title>JS獲取DIV動態高度,並賦值到其style樣式中</title> java
</head> ide
<script type="text/javascript"> ui
function $(id){ htm
return document.getElementById(id) ip
} get
function getHeight() { it
alert($("hidden").offsetHeight + "px"); io
$("pinglun").style.height=$("hidden").offsetHeight + "px";
}
window.onload = function() {
getHeight();
}
</script>
<style>
#hidden { width:100px; background:#99CC00; height:400px; float:left}
#pinglun { width:500px; height:auto; background:#FFCCCC; float:left; margin-left:5px;}
</style>
<body>
<div id="hidden">hidden</div>
<div id="pinglun" >評論數據載入中……</div>
</body>
</html>