<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)
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>
var dd=document.createElement("div")dd.style.cssText="padding:0visibility:hiddenfont-familly:微软雅黑font-size:12px"
dd.innerHTML='测试'
document.body.appendChild(dd)
alert(dd.offsetHeight)
会d出 字体的高度
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)