在应用程序中使用 HtmlCtrl 时,“scrollHeight”未在“onscroll”事件处理程序中更新,但在 I

"scrollHeight" not updated in "onscroll" event handler when using HtmlCtrl in an application but works correctly in IE9

本文关键字:程序 onscroll 事件处理 更新 但在 未在 应用程序 HtmlCtrl scrollHeight      更新时间:2023-09-26

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

<!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" >