如何使用javascript找出div内具有设置高度和overflow:auto的内容的高度?
You can just wrap the content inside another div and then you can use .offsetHeight
on this internal div...
<!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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.