问答详情
源自:9-18 浏览器窗口可视区域大小

浏览器窗口的一些问题

<!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像素?

提问者:guaguaerhao 2016-09-06 11:40

个回答

  • 小丑鱼yang
    2016-09-08 18:02:16
    已采纳

    你body里面没有东西,计算的是body的高度。

  • 小丑鱼yang
    2016-09-08 18:01:24

    <!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>


  • guaguaerhao
    2016-09-07 11:17:56

    。。有意思吗?!哥们?

  • qq_大雄_7
    2016-09-06 20:12:10

    dsdsd