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

这两个document.body.clientWidth和clientHeight为什么不一样

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var w=document.documentElement.clientWidth||document.body.clientWidth;
var h=document.documentElement.clientHeight||document.body.clientHeight;
document.write(w+"*"+h+"<br>")

var w=document.documentElement.clientWidth;
var h=document.documentElement.clientHeight;
document.write(w+"*"+h+"<br>")

var w=document.body.clientWidth;
var h=document.body.clientHeight;
document.write(w+"*"+h+"<br>")

var w=window.innerWidth;
var h=window.innerHeight;
document.write(w+"*"+h+"<br>")

var w=document.body.clientWidth;
var h=document.body.clientHeight;
document.write(w+"*"+h)
</script>
</body>
</html>



提问者:Blueine 2018-05-01 16:35

个回答

  • 慕码人7120386
    2018-05-06 14:58:16

    document.body.clientHeight   网页可见区域高

    document.documentElement.clientHeight  是窗体高