<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head><title>-</title>
</head>
<body>
<div id="someDiv" style="width:50%;border:1px solid #000;"><!--这里面包含一段文字--</div>
<script type="text/javascript">
alert(document.getElementById("someDiv").clientHeight);
alert(document.getElementById("someDiv").offsetHeight);
</script>
</body>
</html>
<html xmlns=" http://www.w3.org/1999/xhtml">
<head><title>-</title>
</head>
<body>
<div id="someDiv" style="width:50%;border:1px solid #000;"><!--这里面包含一段文字--</div>
<script type="text/javascript">
alert(document.getElementById("someDiv").clientHeight);
alert(document.getElementById("someDiv").offsetHeight);
</script>
</body>
</html>
本文通过一个简单的HTML页面示例展示了如何使用JavaScript获取页面中某个元素的高度属性,包括客户端高度(clientHeight)和偏移高度(offsetHeight),这对于理解网页布局及元素尺寸的动态调整具有一定的参考价值。
852

被折叠的 条评论
为什么被折叠?



