簡體   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