当下面的示例代码在 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/