Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在回发期间,在更新面板中保持MULTISELECT ListBox滚动位置,有点有效_Javascript_Asp.net_Listbox_Compatibility - Fatal编程技术网

Javascript 在回发期间,在更新面板中保持MULTISELECT ListBox滚动位置,有点有效

Javascript 在回发期间,在更新面板中保持MULTISELECT ListBox滚动位置,有点有效,javascript,asp.net,listbox,compatibility,Javascript,Asp.net,Listbox,Compatibility,我使用下面的代码来维护一个列表框在回帖中的滚动位置 <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

我使用下面的代码来维护一个列表框在回帖中的滚动位置

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

//帮助在“专业”列表框中保持滚动位置。
var xPos,yPos;
var prm=Sys.WebForms.PageRequestManager.getInstance();
函数BeginRequestHandler(发送方,参数)
{
var listBox=$get(“”);
如果(列表框!=null)
{
xPos=listBox.scrollLeft;
yPos=listBox.scrollTop;
}
}
函数EndRequestHandler(发送方,参数)
{
var listBox=$get(“”);
如果(列表框!=null)
{
listBox.scrollLeft=xPos;
listBox.scrollTop=yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
这在Firefox5或Chrome中非常有效。尽管如此,在IE8/IE9中,每当我在列表框中选择一个项目时,它都会触发回发,并且列表框保持滚动位置。问题是,在回发邮件之后,如果我在框中滚动,或者单击箭头,滚动位置将恢复到列表框的顶部

在Firefox或Chrome中不会出现在滚动启动时的快速恢复


谢谢您的帮助。

可能早该看了,但还是浏览了2071次:

  • s是多重选择的id=“mySelect”名称

  • fs是选定字体的字体大小

    function SetScrollTop(s, fs)
    {
        if(document.getElementById(s) != null)
        {
            document.getElementById(s).scrollTop = (document.getElementById(s).selectedIndex * fs) + 1;
        }
    }
    
使用body onload=“SetScrollTop('mySelect',14)”调用此函数


IE将回帖上的滚动顶部设置为零,因此您需要以某种方式跟踪所选项目(cookie或自制会话处理程序?),以便可以在所选项目上使用“selected”属性。然后在加载过程中设置滚动条顶部。

我尝试了几个类似于您的代码片段,但在我的情况下没有一个代码片段起作用。你的和他们的唯一区别是prm.add_beginRequest(BeginRequestHandler);prm.add_endRequest(EndRequestHandler);他不是在最后。要重置的对象没有声明为变量。怪异!!谢谢你发布这篇文章,它节省了我调试的时间。