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高度
這是DOMDocument對象裏的body子節點和整個節點樹的根節點root。
DOM把層次中的每壹個對象都稱之為節點,就是壹個層次結構,妳可以理解為壹個樹形結構,就像我們的目錄壹樣,壹個根目錄,根目錄下有子目錄,子目錄下還有子目錄。
以HTML超文本標記語言為例:整個文檔的壹個根就是<html>,在DOM中可以使用document.documentElement來 訪問它,它就是整個節點樹的根節點。而body是子節點,要訪問到body標簽,在腳本中應該寫:document.body。