Javascript函数无法获取高度css属性
我有以下网站: 当用户单击底部的“General Commerce”href标记时,应将隐藏内容滑出。除此之外,所有其他标记都正常工作 该函数仅在IE中意外运行。它在Chrome和FF中看起来很好。调试函数时,似乎没有从div中获取Javascript函数无法获取高度css属性,javascript,html,css,Javascript,Html,Css,我有以下网站: 当用户单击底部的“General Commerce”href标记时,应将隐藏内容滑出。除此之外,所有其他标记都正常工作 该函数仅在IE中意外运行。它在Chrome和FF中看起来很好。调试函数时,似乎没有从div中获取height属性: height属性在此行显示为1px: this.height=parseInt(this.obj.style.height) 以下是HTML的简介和函数调用: <table width="100%" border="0" cellspac
height
属性:
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>
你知道我遗漏了什么吗
谢谢。我看到的一件事是你的脚本中出现了错误
这些错误会使JS无法正常运行
查看其中一个,了解如何使用jQuery实现这一点(查看“我们的课程”下的链接)
描述了IE的愚蠢行为导致了您的问题
如果id
和name
有两个值相同的元素(在您的例子中,是idgeneral commerce
的div和链接general commerce
),IE将在使用getElementById时获取其中一个元素
解决方案是更改链接的name属性或div容器的id。您考虑过使用jQuery(或等效工具)吗?这会让事情变得简单很多。马特-我没有。(正如你可能知道的)这是一些非常古老的代码。是的,我看到了。您可以使用jQuery并重写所有动画函数。这并不难,但对解决这些问题真的很有帮助。我点击了你提到的链接,它很好地滑了下来,显示了•证词和评论
@MatthewJordan via IE?我对IE 9有意见。铬和FF看起来不错。
$('.lgroup').on('click', function () {
if ($(this).hasClass('directLink')) {
return true
} else {
$('.links').slideUp();
$('.lgroup').removeClass('lactive');
if ($(this).next().css('display') == 'block') {
$(this).next().slideUp()
} else {
$(this).addClass('lactive').next().slideDown()
}
}
});