IE8的scrollHeight属性导致问题
我有一个 DIV 元素,我可以在其中添加和删除内容,并且根据我的阅读,scrollHeight 属性是 DIV 内容高度的度量。我有一部分 javascript 代码,根据scrollHeight 属性将 DIV 设置为特定高度:
if (div.scrollHeight <= 25)
{
div.style.height = "25px";
}
else if (div.scrollHeight > 25)
{
div.style.height = "50px";
}
该代码适用于 IE6 和 IE7,但是当它在 IE8 中运行时,一旦样式高度设置为 50px 的值,即使我删除了 DIV 的一些内容以使其适合 25px 高度,scrollHeight 属性仍然返回 50px 的值。那么问题就出在IE8下DIV展开后尺寸并没有收缩到更小的尺寸。我可以寻求帮助来解决这个问题吗?
I have a DIV element where I can add and remove contents from it, and based on my readings, the scrollHeight property is a measure of the DIV's content height. I have a portion of javascript code that sets the DIV to a specific height based on the scrollHeight property:
if (div.scrollHeight <= 25)
{
div.style.height = "25px";
}
else if (div.scrollHeight > 25)
{
div.style.height = "50px";
}
The code works with IE6 and IE7, but when it is run in IE8, once the style height is set to a value of 50px, the scrollHeight property keeps returning a value of 50px even though I removed some of the DIV's content to make it fit a 25px height. So the problem is that the size of the DIV does not contract to the smaller size after its expansion under IE8. May I get help with fixing this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许某些元素没有从 IE 的节点列表中完全删除?
尝试将它们设置为
null
,然后重新加载内容。Maybe some of the elements are not totally removed from IE's nodelist?
Try to set them as
null
and then reload the content.