原来HTML里是document.body
XHTML里是document.documentElement
都指的是<body>节点(OR元素)
可以这样兼容:
function getBodyObj()
{
return (document.documentElement) ? document.documentElement : document.body ;
}
在DHTML文档中对documentElement的说明是:Object that receives the reference to the document element,The root node of a typical HTML document is the html object.
body
Microsoft® Internet Explorer 6 的新增内容
当你使用 !DOCTYPE 声明指定标准兼容模式的时候,此对象将不再代表文档内容所渲染的整个表面。该对象当然可从其内容中获得其大小,但你也可以像 div 对象那样精确设置其大小。
也就是说在HTML4.0标准下用document.body,在XHTML标准下就要换成document.documentElement。XHTML下document.body仅仅表示body对象,而不能代表文档内容所渲染的整个表面。HTML下document.body.clientHeight表示浏览器的可视高度,XHTML下则是document.documentElement.clientHeight。document.body.clientHeight在XHTML下仅表示body的可视高度。在HTML4.0下用document.body.scrollTop;而在XHTML下则是document.documentElement.scrollTop,之前的document.body.scrollTop是恒为0的。