"網(wǎng)頁(yè)內(nèi)容實(shí)際高度小于 clientHeight 時(shí),scrollHeight 返回 clientHeight 。" 教程上是這么說的,然而下面的代碼好像打臉了。。誰能告訴我為啥啊?多謝!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
document.write(document.body.scrollWidth + "<br>");
document.write(document.body.scrollHeight + "<br>");
document.write(document.body.clientWidth + "<br>");
document.write(document.body.clientHeight + "<br>");
</script>
</body>???
</html>
2015-07-22
不同瀏覽器存在不同效果。
var bodyW = document.documentElement.clientWidth||document.body.clientWidth;
var bodyH = document.documentElement.clientHeight||document.body.clientHeight;
//body的寬高,body是IE7之前的版本。