简体   繁体   English

高度检测不起作用

[英]detection of height doesn't work

I have this simple script:我有这个简单的脚本:

var o = document.getElementById("content");

if (o.clientHeight == "372") {
  o.style.height = "328px";
  o.style.marginBottom = "44px";

} else {
  o.style.height = "214px";
  o.style.marginBottom = "32px";
}

but somehow the ELSE always executes, even if the initial height of my div is 372px... can anyone help me?但不知何故 ELSE 总是执行,即使我的 div 的初始高度是 372px ......有人可以帮助我吗?

clientHeight takes padding into account. clientHeight将填充考虑在内。 You may want to use scrollHeight , offsetHeight , or style.height , depending on your needs.您可能需要使用scrollHeightoffsetHeightstyle.height ,具体取决于您的需要。 Note that style.height does not return an integer like the others.请注意, style.height不会像其他人一样返回 integer。

http://help.dottoro.com/ljcadejj.php http://help.dottoro.com/ljcadejj.php

if clientHeight does return integer, try to remove quotes like this:如果clientHeight确实返回 integer,请尝试删除这样的引号:

var o = document.getElementById("content");
    if(o.clientHeight==372){
    o.style.height="328px";
    o.style.marginBottom="44px";}
    else{o.style.height="214px";
    o.style.marginBottom="32px";}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM