區別:
body是DOM物件裡的body子節點,即
標籤;
documentElement 是整個節點樹的根節點root,即 標籤;
沒使用DTD情況即怪異模式BackCompat下:
代碼如下:
.clientHeight=0document.body.clientHeight=618
複製程式碼>
程式碼如下:
document.documentElement.clientHeight=618 document.body.clientHeight=28(表示內容的高度)
因此提取瀏覽器的尺寸是要注意了。可參考以下程式碼:
複製程式碼
程式碼如下:
if (document.compatent. "BackCompat") {
cWidth = document.body.clientWidth;
cHeight = document.body.clientHeight;
sWidth = document.body.scrollWidth;
Height = document. 🎜>sLeft = document.body.scrollLeft;
sTop = document.body.scrollTop;
}
else { //document.compatMode == "CSS1Compat"
else { //document.compatMode == "CSS1Compat"
ccliidth = docum. ;
cHeight = document.documentElement.clientHeight;
sWidth = document.documentElement.scrollWidth;
sHeight = document.documentElement.scrollHeight;
sHeight = document.documentElement.scrollHeight; body.scrollLeft : document.documentElement.scrollLeft;
sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop
; ;