detection of height doesn't work
I have this simple script:
var o = document.getElementById("content");
if (o.clientHeight == "372开发者_如何学JAVA") {
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?
clientHeight
takes padding into account. You may want to use scrollHeight
, offsetHeight
, or style.height
, depending on your needs. Note that style.height
does not return an integer like the others.
http://help.dottoro.com/ljcadejj.php
if clientHeight
does return integer, try to remove quotes like this:
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";}
精彩评论