Javascript JS函数在FF和Safari中非常有效,但在IE9中需要很长时间

Javascript JS函数在FF和Safari中非常有效,但在IE9中需要很长时间,javascript,Javascript,你能看出它在FF和Safari中运行良好的原因吗,但在IE9中运行时,它会完全失效吗?这需要很长时间,几乎会挂起浏览器。谢谢 这是一个按键后刷新列表的功能。该函数清除列表,然后通过全局定义的数组进行线性搜索,并将匹配项添加回列表 function handleKeyUp() { var selectObj, textObj, componentListLength; var i, searchPattern, numShown; // Set references to

你能看出它在FF和Safari中运行良好的原因吗,但在IE9中运行时,它会完全失效吗?这需要很长时间,几乎会挂起浏览器。谢谢

这是一个按键后刷新列表的功能。该函数清除列表,然后通过全局定义的数组进行线性搜索,并将匹配项添加回列表

function handleKeyUp()
{
    var selectObj, textObj, componentListLength;
    var i, searchPattern, numShown;

    // Set references to the form elements
    selectObj = document.form1.componentselect;
    textObj = document.form1.componentinput;

    // Remember the function list length for loop speedup
    componentListLength = componentlist.length;

    // Set the search pattern depending
    if(document.form1.componentradio[0].checked == true)
    {
        searchPattern = "^"+textObj.value;
    }
    else
    {
        searchPattern = textObj.value;
    }

    // Create a regular expression
    re = new RegExp(searchPattern,"gi");
    // Clear the options list
    selectObj.length = 0;

    // Loop through the array and re-add matching options
    numShown = 0;
    for(i = 0; i < componentListLength; i++)
    {
        if(componentlist[i].search(re) != -1)
        {
            selectObj[numShown] = new Option(componentlist[i],"");
            numShown++;
        }
    }
}

我觉得有两件事很可疑:

// Clear the options list
selectObj.length = 0;
// should be
selectObj.options.length = 0;


// Next thing, adding them back
selectObj[numShown] = new Option(componentlist[i],"");
// should be
selectObj.options[numShown] = new Option(componentlist[i],""); 

你能在脚本调试器中一步一步地检查它,并试着找出是什么花了这么长时间吗?另外,componentListLength的值是多少?你正在处理一些庞大的列表吗?列表中大约有6500项。而且,IE遇到的问题是“for”循环。例如,在FF中,我可以在调试器中快速跳过它。然而,IE必须在相当长的一段时间内完成循环。