如何用“height = auto”定义计算div的高度

时间:2023-02-01 08:38:39

I need to calculate the height of this div with Javascript.

我需要用Javascript计算这个div的高度。

When i wrote this script:

当我写这个脚本时:

function getMainDivHeight() {
    var num = document.getElementById('up_container').style.height;
    return num;
}

this script returns auto

此脚本返回auto

I need the height of the div after it change.

改变后我需要div的高度。

Thanks ! ! !

谢谢 ! ! !

1 个解决方案

#1


5  

You need to get the offsetHeight property:

你需要获得offsetHeight属性:

function getMainDivHeight() { 
 var num = document.getElementById('up_container').offsetHeight; 
 return num; 
}

#1


5  

You need to get the offsetHeight property:

你需要获得offsetHeight属性:

function getMainDivHeight() { 
 var num = document.getElementById('up_container').offsetHeight; 
 return num; 
}