亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

網頁尺寸offsetHeight

?<script type="text/javascript">

var w= document.documentElement.offsetWidth;

var h= document.documentElement.offsetHeight;

//法一 ? ?

? ? document.write("方法一"+"<br/>"+"網頁內容的寬度為:"+w+"<br ?/>"+"網頁內容的高度為:"+h);

//法二

? ?document.write("<br />"+"方法二"+"<br/>");

? ?document.write("網頁內容的寬度為:"+document.body.offsetWidth+"<br ?/>");

? ?document.write("網頁內容的高度為:"+document.body.offsetHeight);

</script>

為什么這兩個方法的輸出結果不一樣》?

正在回答

1 回答

你是講兩種測試方法都放在一個demo中的吧,因為document.write的輸出結果會占用網頁打的內容高度,所以后一個測試中輸出的網頁的高度會增加兩行的行高.你也可以試試在<body></body>增加些內容看看數據變化就知道原因了.

<!DOCTYPE?HTML>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">?

</head>
<body>
?<h2>測試網頁尺寸</h2>
?<h2>11111111111</h2>
?<h2>數值會隨著body標簽的內容而改變</h2>
?<script?type="text/javascript">
document.write(document.body.offsetHeight+"<br?/>");
document.write(document.body.offsetWidth+"<br?/>");
document.write(document.body.offsetHeight+"<br?/>");
document.write(document.body.offsetWidth+"<br?/>");
document.write(document.body.offsetHeight+"<br?/>");
document.write(document.body.offsetWidth+"<br?/>");
</script>
</body>
</html>

http://img1.sycdn.imooc.com//58cf50f70001463e03870341.jpg


0 回復 有任何疑惑可以回復我~
#1

慕的地6791964 提問者

非常感謝!
2017-04-20 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

網頁尺寸offsetHeight

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號