[英]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
将填充考虑在内。 您可能需要使用scrollHeight
、 offsetHeight
或style.height
,具体取决于您的需要。 请注意, style.height
不会像其他人一样返回 integer。
如果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.