<!DOCTYPE html>
<html>
<body>
<table align="right">
<tr>
<th> Row 1 </th>
</tr>
<tr>
<th> Row 2 </th>
</tr>
</table>
</body>
</html>
我有一个带有2行的简单表。该表具有align =“ right”属性。此参数添加属性float:right;。在运行时,将车身高度设置为0。
我在某些计算中使用了身高。因此获得实际高度非常重要。
所以我的问题是,我如何获得身体的实际高度?
var table = document.getElementById('mytable');
//variant 1
var rect = table.getBoundingClientRect();
var height_var1 = rect.height;
// variant 2
var height_var2 = table.clientHeight;
<!DOCTYPE html>
<html>
<body>
<table id="mytable" align="right">
<tr>
<th> Row 1 </th>
</tr>
<tr>
<th> Row 2 </th>
</tr>
</table>
</body>
</html>