繁体   English   中英

高度检测不起作用

[英]detection of height doesn't work

我有这个简单的脚本:

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";
}

但不知何故 ELSE 总是执行,即使我的 div 的初始高度是 372px ......有人可以帮助我吗?

clientHeight将填充考虑在内。 您可能需要使用scrollHeightoffsetHeightstyle.height ,具体取决于您的需要。 请注意, style.height不会像其他人一样返回 integer。

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

如果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