DOM获取body宽度高度时问题
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>未命名</title>
<script>
window.onload = function(){
//alert(document.documentElement.offsetHeight);
//这个是窗口总宽度2000如果有margin会加上margin
//IE下弹出了窗口的高度720并不是body的高度
//document.documentElement 和 document.body
//document.documentElement:返回的是html元素
//document.body:返回的是body元素
//在浏览器版本不兼容的情况下可以用其他一些方法做出兼容性
//如: document.documentElement.scrollTop || document.body.scrollTop
//alert(document.body.clientHeight); //IE和谷歌都弹出2000不包含margin值
document.onclick = function(){
//alert(document.documentElement.scrollTop); //IE可用 360下值为0
//alert(document.body.scrollTop); //360下可以 IE值为0
//alert(document.body.scrollTop || document.documentElement.scrollTop); //IE 360兼容
//offsetHeight 等于width + padding + border
//clientHeight 等于width + padding
//alert(document.documentElement.clientHeight); //IE:716 360:737
//alert(document.body.offsetHeight); //360:2000 IE8:2000;
//document.documentElement.clientHeight 只能计算窗口的高度
};
};
</script>
<style>
#div1{height:200px;width:300px;background:red;border:5px solid #333;}
</style>
</head>
<body style="height:2000px;">
<div id="div1">ds</div>
</body>
</html>