guaguaerhao
2016-09-06 11:40
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
*{
margin:0;padding:0;}
</style>
</head>
<body>
<script type="text/javascript">
document.write(document.body.clientWidth);
document.write(' ');
document.write(document.body.clientHeight);
</script>
</body>
</html>
为什么这个一直都是
document.write(document.body.clientHeight);
18像素或者22像素?
你body里面没有东西,计算的是body的高度。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var ww = window.innerWidth;
var wh = window.innerHeight;
document.write(ww+'*'+wh+'<br />');
var dw = document.documentElement.clientWidth;
var dh = document.documentElement.clientHeight;
document.write(dw+'*'+dh+'<br />');
var bw = document.body.clientWidth;
var bh = document.body.clientHeight;
document.write(bw+'*'+bh+'<br />');
var w = document.documentElement.clientWidth || document.body.clientWidth;
var h = document.documentElement.clientHeight || document.body.clientHeight;
document.write(w+'*'+h+'<br />');
var tw = window.innerWidth || document.body.clientWidth;
var th = window.innerHeight || document.body.clientHeight;
document.write(tw+'*'+th+'<br />');
var tw = window.innerWidth || document.documentElement.clientWidth;
var th = window.innerHeight || document.documentElement.clientHeight;
document.write(tw+'*'+th+'<br />');
</script>
</body>
</html>
。。有意思吗?!哥们?
dsdsd
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题