【发布时间】:2011-09-30 19:02:44
【问题描述】:
我正在使用以下代码来维护 ListBox 在回发中的滚动位置。
<script type="text/javascript">
// Helps maintain scroll position on the Specialty list box.
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args)
{
var listBox = $get('<%= Special.ClientID %>');
if (listBox != null)
{
xPos = listBox.scrollLeft;
yPos = listBox.scrollTop;
}
}
function EndRequestHandler(sender, args)
{
var listBox = $get('<%= Special.ClientID %>');
if (listBox != null)
{
listBox.scrollLeft = xPos;
listBox.scrollTop = yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
</script>
这在 Firefox 5 或 Chrome 中完美运行。虽然,在 IE8/IE9 中,每当我在列表框中选择一个项目时,它都会触发回发并且列表框保持滚动位置。问题是,在回帖后,如果我在框中滚动,或者单击箭头,滚动位置会重新回到列表框的顶部!
在 Firefox 或 Chrome 中不会发生滚动开始时的回弹。
感谢您的帮助。
【问题讨论】:
-
我尝试了几个与您类似的代码 sn-ps,但在我的情况下都没有。你和他们的唯一区别是 prm.add_beginRequest(BeginRequestHandler); prm.add_endRequest(EndRequestHandler);不是在最后。并且要重置的对象未声明为 var。诡异的!!感谢您发布此内容,它节省了我调试的时间。
标签: javascript asp.net listbox compatibility