[英]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.