我有以下站点:
http://www.pachamber.org/www/advocacy/index.php
当用户点击底部的“General Commerce”href 标签时,应该会滑出隐藏的内容。除此标签外,所有其他标签均正常工作。
该函数仅在 IE 中表现出意外。它在 Chrome 和 FF 中看起来没问题。调试函数的时候,好像没有抓不到height
来自 div 的属性:
<div id="general" style="display: none; height: 30px; overflow: hidden">
height
属性在此行显示为 1px:
this.height = parseInt(this.obj.style.height);
这是 HTML 代码片段和函数调用:
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td colspan="2" style="width: 100%;">
<div class="subheading2" style="border-bottom: thin solid gray; cursor: pointer; color: #000099" onClick="doSlideOut('general');"><a name="general"></a>General Commerce</div>
</td>
</tr>
</table>
<div id="general" style="display: none; height: 30px; overflow: hidden">
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="53%">
• <a href="gc/testimony/index.php" >Testimony & Comments</a>
</td>
<td width="47%"> </td>
</tr>
</table>
</div>
知道我遗漏了什么吗?
谢谢。
最佳答案
Beware of id and name attribute when using getElementById in Internet Explorer 描述了导致您的问题的 IE 的愚蠢行为。
如果有两个元素的 id
和 name
具有相同的值(在您的情况下,它是 id 为 general-commerce
和链接 General Commerce
) IE 将在使用 getElementById 时获取其中一个。
解决方案是更改链接的名称属性或 div 容器的 ID。
关于Javascript 函数无法获取高度 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339772/