如何通过javascript找出设置高度和溢出的div内容的高度:auto?
答案 0 :(得分:1)
您可以将内容包装在另一个div中,然后您可以在此内部div上使用.offsetHeight
...
<!DOCTYPE HTML>
<html>
<body>
<div style="background-color:#EEEEEE; height:400px; overflow:auto; width:100%">
<div id="container">
<p>The quick brown fox jumps over the lazy dog</p>
<p>The quick brown fox jumps over the lazy dog</p>
... snip ...
<p>The quick brown fox jumps over the lazy dog</p>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
</div>
<script>
setTimeout(function() {
var container = document.getElementById("container");
alert("Container height = " + container.offsetHeight);
}, 1000);
</script>
</body>
</html>