<html>
<head>
</head>
<body style="height:400px">
<div id="div1">12312</div>
<script type="text/javascript">
document.getElementById("div1").style.height=document.body.style.height
alert(document.getElementById("div1").style.height)
//如果body,没有设置样式,这个高度就为空
document.getElementById("div1").style.height=document.body.clientHeight
alert(document.getElementById("div1").style.height)
//如果设置了样式,offsetHeight就等于样式的height否则等于clientHeight
document.getElementById("div1").style.height=document.body.offsetHeight
alert(document.getElementById("div1").style.height)
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)