简体   繁体   English

JS函数在FF和Safari中效果很好,但在IE9中花费很长时间

[英]JS function works great in FF and Safari, but takes a VERY long time in IE9

Can you see any reason it would work fine in FF and Safari, but when run in IE9 it completely craps out? 您能看到任何原因在FF和Safari中正常运行,但在IE9中运行时却完全崩溃了吗? It takes forever and almost hangs the browser. 它要花很多时间,并且几乎会使浏览器挂起。 Thanks! 谢谢!

This is a function that refreshes a list after a keypress. 此功能在按键后刷新列表。 The function clears the list, and then does a linear search through the globally defined array and adds the matches back to the list. 该函数清除列表,然后在全局定义的数组中进行线性搜索,并将匹配项添加回列表中。

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++;
        }
    }
}

Two things that look fishy to me: 对我来说,两点看上去很糟:

// 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],""); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于检测浏览器宽度和高度的 JS 适用于 Chrome 和 Safari,但不适用于 IE9 或 FF9 - JS to detect browser width and height works in Chrome & Safari but not IE9 or FF9 JavaScript搜索功能在Chrome,Safari和Opera中运行良好,但在IE和Firefox中永远存在 - JavaScript search function works great in Chrome, Safari, and Opera, but takes forever in IE and Firefox 在IE9中未检测到视图模型功能绑定,但在FF和Chrome中有效 - View Model Function binding not detected in IE9 but works in FF and Chrome JS适用于FF,但不适用于IE - JS works in FF but not in IE JS可以在Safari中使用,但不能在IE9中使用-有人可以帮助实现此功能吗? - JS works in Safari but not IE9 - Can anyone help to make this work? 在ie9和ff4中工作-不在ie7或ie 8中吗? - works in ie9 and ff4 - not in ie7 or ie 8? Javascript适用于FF / IE,但不适用于Chrome / Safari - Javascript works in FF / IE but not Chrome / Safari 未在IE7和8上显示的Ajax内容 - 在IE9和FF上工作 - Ajax content not displaying on IE7 & 8 - WORKS on IE9 & FF 我的 Javascript 适用于 IE FF 和 Safari,但不适用于 Chrome - My Javascript works on IE FF & Safari, but not Chrome window.location在IE9和FF中的工作方式不同 - window.location does not works the same way in IE9 and FF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM