在寻找找出窗口高度的方法时,我了解到“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/