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

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

為什么兩種方法同一瀏覽器同一運行環境,結果不一樣

<!DOCTYPE HTML>

<html>

<head>

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

</head>

<body>

<script type="text/javascript">

document.write("方法一:"+"<br>"+"實際高度:"+document.body.scrollHeight+" "+"實際寬度:"+document.body.scrollWidth+"<br>");

?document.write("方法二:"+"<br>"+"實際高度:"+document.documentElement.scrollHeight+" "+"實際寬度:"+document.documentElement.scrollWidth);

</script>

</body> ? ?

</html>


正在回答

1 回答

document.body和document.documentElement比較:

???? document.body是DOM中Document對象里的body節點, document.documentElement是文檔對象根節點(html)的引用。
???? IE在怪異模型(quick mode)下document.documentElement無法正確取到clietHeight scrollHeight等值,比如clietHeight=0。可以見IE的怪異模型并沒有把html作為盒子模型的一部分,好在現在很少使用怪異模型。(注:如果頁面沒寫DTD或寫的不對,IE6默認使用怪異模型解析頁面)

document.body.scrollHeight和document.documentElement.scrollHeight的區別:

???? document.body.scrollHeight是body元素的滾動高度,document.documentElement.scrollHeight為頁面的滾動高度,且 document.documentElement.scrollHeight在IE和Firefox下還有點小差異。
?????IE?: document.documentElement.scrollHeight = document.body.scrollHeight + marginTop bottom高度 + 上下border寬度
?????firefox?: document.documentElement.scrollHeight = document.body.scrollHeight + marginTop bottom高度


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

漩渦鳴人007 提問者

非常感謝!
2016-03-15 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么兩種方法同一瀏覽器同一運行環境,結果不一樣

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

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

幫助反饋 APP下載

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

公眾號

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