javascript - 在应用程序中使用 HtmlCtrl 时,"scrollHeight"未在 "onscroll"事件处理程序中更新,但在 IE9 中正常工作

标签 javascript internet-explorer dom-events onscroll htmlcontrols

当下面的示例代码在 IE9 中加载时,它可以正常工作,但是当在应用程序的 html 控件中加载时,scrollHeight 没有在 onscroll 事件处理程序中更新,当我更改时处理程序中的 innerHTML 内容,因此不会显示警报。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
function f()
{
    var nBodyHeightOld = document.getElementById("div1").scrollHeight;
    document.getElementById("div1").innerHTML += '<div>It is a test!</div>';
    if (document.getElementById("div1").scrollHeight != nBodyHeightOld)
        alert('scrollHeight changed!');
}
</script>
</head>
<body>
<div id='div1' style='overflow:scroll; height:300px' onscroll="f()">
    <div style='height:400px'></div>
</div>
</body>
</html>

最佳答案

因为应用程序使用 IE8。要强制应用程序使用 IE9,请将元标记添加到 html:

<meta http-equiv="X-UA-Compatible" content="IE=9" >

关于javascript - 在应用程序中使用 HtmlCtrl 时,"scrollHeight"未在 "onscroll"事件处理程序中更新,但在 IE9 中正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10329059/

相关文章:

javascript - 混合 javascript 函数声明样式

javascript - mailto:创建电子邮件时,Internet Explorer 在 Outlook 中反转时间字符串

javascript - 如何在元素上发送双击事件?

javascript - CSS Transitions - 为什么它们不会在新添加内容的类更改时触发?

javascript - 使用 node-redis 获取多个键

javascript - SVG 在最大尺寸处拉伸(stretch)然后填充其余尺寸

javascript - IE js 与 event.target 发生错误!==

internet-explorer - 什么是 IE 开发人员工具栏中的 &lt;!&gt; 元素

javascript - 在 React 中,onChange 和 onInput 有什么区别?

javascript - 突出显示悬停元素的事件?