document.body.scrollTop,document.body.clientHeight的值为0的问题

来源:互联网 发布:淘宝商城需要多少钱 编辑:程序博客网 时间:2024/05/17 07:47

憋了我好久 终于在网上找到了答案:
在写个漂浮广告时遇到document.body.scrollTop和document.body.clientHeight为零的问题,在网上找到了原因:是因为html/jsp文件头部加了文档类型。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

解决办法可以有两个(使用第二个好点)

1.去掉头部文档类型。

2.把document.body.scrollTop和document.body.scrollLeft这两个家伙改个名字:

document.documentElement.scrollTop 和document.documentElement.scrollLeft。

当然document.body.clientWidth和document.body.clientHeight也要改名字了,改为:document.documentElement.clientWidth和document.documentElement.clientHeight


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lgh731/archive/2009/03/17/3998949.aspx

原创粉丝点击