嗨,我有这个HTML,它的末尾有脚本来显示偏移高度。对于最外面的div元素,offsetHeight似乎为0。不知道为什么。请分享你的想法。如何获得div元素的正确高度。
另请注意,这只发生在Internet Explorer 11上。
<HTML>
<HEAD>
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<div id="temp">
<div align="left" style="font-family: Arial; cursor: default;">
<table align="left" id="defaulttable" style="width: 720px; font-family: Arial; font-size: 12pt; cursor: default; background-color: #ffffff;" border="0" cellspacing="2" cellpadding="2">
<tbody style="font-family: Arial; font-size: 12pt;">
<tr style="font-family: Arial; font-size: 12pt;">
<td width="30%" valign="top" style="width: 195px; font-family: Arial; font-size: 12pt;">
<div style="font-family: Arial; font-size: 12pt;">
<strong style="font-family: Arial; font-size: 12pt;">
<span style="font-family: Arial; font-size: 12pt; cursor: default;">
<br style="font-family: Arial; font-size: 12pt;">
</span>
</strong>
</div>
</td>
<td valign="top" style="width: 270px; font-family: Arial; font-size: 12pt;">
<h1 align="center" style="font-family: Arial; font-size: 12pt; cursor: default;">
<span style="font-family: Arial; font-size: 14pt; cursor: default;">
<br />
Test1
<br style="font-family: Arial;">
<br style="font-family: Arial;font-size: 12pt;">
<div align="center" style="font-family: Arial; cursor: default;">
<input name="C4FF503C-B000-0001-1536-FF951CE01ADB" id="C4FF503C-B000-0001-1536-FF951CE01ADB" style="width: 161px; height: 22px; text-transform: capitalize; font-family: Arial; font-size: x-small; font-weight: bold; text-decoration: underline; cursor: default;" type="text" size="1" value="Type Name Here" displayon="all,null,null,null"></div>
</span></h1>
</td>
<td width="30%" valign="top" style="width: 245px; font-family: Arial; font-size: 12pt;">
<div style="font-family: Arial; font-size: 12pt; cursor: default;"> </div>
<div style="font-family: Arial; font-size: 12pt; cursor: default;"> Test2<br style="font-family: Arial; font-size: 12pt;" />
<div align="center" style="font-family: Arial;"><input id="C4E8747A-EA40-0001-4B11-1B4F9010B9A0" style="width: 229px; height: 68px; font-family: Arial; font-size: 12pt; cursor: default;" type="text" size="25" value=" " displayon="all,null,null,null"></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<script language="JavaScript">
alert(document.getElementById("temp").offsetHeight);
</script>
</BODY>
</HTML>