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