[英]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.