当网站声明为<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">时,document.body.scrollTop 的值没有变化,一直为0。
解决办法:用 document.documentElement 替换掉 javascript 中的 document.body 。
因此在使用 document.body.scrollTop 时不能为网页声明 DOCTYPE 类型,对于声明了DOCTYPE 类型的网页则使用 document.documentElement.scrollTop 就行。
解决办法:用 document.documentElement 替换掉 javascript 中的 document.body 。
因此在使用 document.body.scrollTop 时不能为网页声明 DOCTYPE 类型,对于声明了DOCTYPE 类型的网页则使用 document.documentElement.scrollTop 就行。