您的位置:首页 > Web前端 > CSS

JS获取DIV动态高度,并赋值到其style样式中

2014-08-16 00:52 459 查看
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS获取DIV动态高度,并赋值到其style样式中</title>
</head>
<script type="text/javascript">
function $(id){
return document.getElementById(id)
}
function getHeight() {
alert($("hidden").offsetHeight + "px");
$("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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: