在寻找找出窗口高度的方法时,我发现“document.body.clientHeight”很有用。我在不同的情况下尝试过,一切都失败了。
失败意味着它在所有窗口高度都返回相同的值。

最后我删除了 DOCTYPE 声明

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

一切顺利。现在它返回确切的结果。

甚至 html5 DOCTYPE
<!DOCTYPE html>

返回无效结果。

我在不同的浏览器(Chrome、Opera、Firefox 和 IE)中检查过它。

这是什么原因?
使用 document.body 时还有其他限制吗?
在同一场景下还有其他东西(变量、标签、方法、用法等)吗?

谢谢你。

最佳答案

试试这个

document.getElementById("viewheight").innerHTML = window.innerHeight


   <!DOCTYPE html>,  puts the document into standards mode.

adding + "px" to the end of the size setting line
  document.getElementById("viewheight").innerHTML = document.body.clientHeight + "px";

关于javascript - document.body.clientHeight 返回无效结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21575855/

10-16 21:08