Javascript Internet Explorer在选择列表框中设置scrollTop后出现混乱

Javascript Internet Explorer在选择列表框中设置scrollTop后出现混乱,javascript,html,internet-explorer,html-select,Javascript,Html,Internet Explorer,Html Select,以下内容已在Windows XP上的Internet Explorer 8、Windows 7上的Internet Explorer 9和Windows 7上的Chrome 17中进行了测试。它可以在Chrome中正常工作,但不能在IE中正常工作 简单地说,当HTML选择对象(listbox)的scrollTop属性出现错误时,IE似乎会感到困惑。设置后,IE将滚动框放置在正确的位置,并显示该scrollTop值的正确值。但是,在设置scrollTop后单击滚动条,会将显示跳转到列表中的其他位置

以下内容已在Windows XP上的Internet Explorer 8、Windows 7上的Internet Explorer 9和Windows 7上的Chrome 17中进行了测试。它可以在Chrome中正常工作,但不能在IE中正常工作

简单地说,当HTML选择对象(listbox)的scrollTop属性出现错误时,IE似乎会感到困惑。设置后,IE将滚动框放置在正确的位置,并显示该scrollTop值的正确值。但是,在设置scrollTop后单击滚动条,会将显示跳转到列表中的其他位置

有人知道如何让IE尊重scrollTop的价值,从而最终用户从scrollTop位置开始滚动吗

我不会做很多javascript编程,所以请温柔一点。:)

如果运行此操作,请输入介于0和最大scrollTop之间的值,按Go To scrollTop按钮,然后按滚动条上的向上或向下箭头。当它工作时,您将从scrollTop按钮显示的位置向上或向下移动一英寸。当它不起作用时,您将一直滑回列表的顶部,或者如果您在按下按钮之前已经手动滚动,则将滑回与您所在位置的随机距离

以下是在线代码:

以下是内联代码:

<html>
<form id="myForm">
<select name='ListBox' id='LB1' size=10></select><BR>
Set scrollTop Value: <input type="text" id="scrollTopValue" value="1000" onkeypress="return noenter()"/>
<br><br><br>
<button type="button" onclick="updateNumbers()">Update Numbers</button>
<button type="button" onclick="goToScrollTop()">Go To scrollTop</button>
<br><br><br>
<select name='ListBox' id='LB2' size=10" ></select><BR>
</form>

<script type="text/javascript">

window.onload = initialize();

function initialize() {
    var i;
    var select1 = document.getElementById( 'LB1' );

    for(i = 0; i < 100; i++) 
    {       
        try
        {
            select1.add(new Option(i));
        }
        catch(ex)
        {
            select1.add(new Option(i),select1.options[null]); // for older IE versions
        }   
    }
    updateNumbers();
}

function goToScrollTop() {
    var select1 = document.getElementById('LB1');
    var input1 = document.getElementById('scrollTopValue');

    if (input1.value < 0 || input1.value > (select1.scrollHeight - select1.clientHeight) || isNaN(input1.value))
    {
        alert("scrollTop value must be between 0 and " + (select1.scrollHeight - select1.clientHeight));
    }
    else
    {
        select1.scrollTop = input1.value;
    }
}


function updateNumbers() {
    var select1 = document.getElementById( 'LB1' );
    var select2 = document.getElementById( 'LB2' );

    select2.length = 0;
    try
    {
        select2.options.add(new Option('scrollTop = ' + select1.scrollTop));
        select2.options.add(new Option('scrollHeight = ' + select1.scrollHeight));
        select2.options.add(new Option('clientHeight = ' + select1.clientHeight));
        select2.options.add(new Option('scrollHeight - clientHeight = max scrollTop = ' + (select1.scrollHeight - select1.clientHeight)));

        select2.options.add(new Option('listbox.length = ' + select1.length));
    }
    catch(ex)
    {
        alert(ex);
    }
}

function noenter() {
  return !(window.event && window.event.keyCode == 13); }

</script>
</html>


设置滚动上限值:


更新号码 转到scrollTop



嗨,大卫,你有这个工作吗?我只是有同样的问题…嗨,大卫,你有这个工作吗?我只是有同样的问题。。。