Javascript IE 8,Jquery操作上的堆栈溢出
我使用以下代码根据文本框中的输入筛选表。在其他浏览器上,我没有收到这样的错误,但在IE 8(未在lower上测试)上,我收到错误:Javascript IE 8,Jquery操作上的堆栈溢出,javascript,jquery,stack,Javascript,Jquery,Stack,我使用以下代码根据文本框中的输入筛选表。在其他浏览器上,我没有收到这样的错误,但在IE 8(未在lower上测试)上,我收到错误: Out of stack space Line 4 character 26207 jquery.min.js 以下是导致问题的当前代码: var timeout; function sort(){ clearTimeout(timeout); var value = document.getElementById('searchBarText
Out of stack space Line 4 character 26207 jquery.min.js
以下是导致问题的当前代码:
var timeout;
function sort(){
clearTimeout(timeout);
var value = document.getElementById('searchBarText').value;
timeout = setTimeout(
function(){$("#searchTable tr").each(function() {
var id = " "
$row = $(this);
$row.each(function( i ) {
$("td", this).each(function( j ) {
id+="".concat($(this).text());
});
});
id = id.replace(/\s+/g, ' ');
id = id.replace(/(\d+)/g, '');
if (id.toLowerCase().indexOf(value.toLowerCase()) == -1) {
$row.hide();
if(value.length < 3){
$("#searchBarText").css('border', '2px red solid')
}else{
$("#searchBarText").removeAttr('style')
}
}
else if(value!="" &&value.length >= 3) {
$("#searchBarText").removeAttr('style')
$("#topTable").css('margin-top', '0px')
$("#searchIcon").css('color', '#26466D')
$("#searching").fadeIn();
$row.show();
}else{
if(value.length > 0){
$("#searchBarText").css('border', '2px red solid')
}else{
$("#searchBarText").removeAttr('style')
}
$("#searchIcon").removeAttr('style')
$("#searching").slideUp();
$("#topTable").css('margin-top', '-5px')
$row.hide();
}
})},400);
}
我绝对不是javascript专家,因此非常感谢所有帮助
更新:原来是向上滚动jquery方法,用show替换了它,它已经全部设置好了当您只有一行时,不需要迭代每一行,只需直接选择单元格并迭代它们
$row = $(this);
$row.find("td").each(function( i ) {
id+=$(this).text();
});
或
甚至
$row = $(this);
id += $row.text();
当您只有一行时,不需要迭代每一行,只需直接选择单元格并迭代即可
$row = $(this);
$row.find("td").each(function( i ) {
id+=$(this).text();
});
或
甚至
$row = $(this);
id += $row.text();
首先,我建议不要在同一操作中多次选择同一元素,每次通过jQuery选择某个元素时,都必须遍历DOM才能找到它。 例如,查找一次#searchBarText并重复使用它,如下所示:
var $searchBarText = $('#searchBarText');
$row = $(this);
$row.children('td').each(function () {
id += $(this).text();
});
至于你提到的代码块,我将这样做:
var $searchBarText = $('#searchBarText');
$row = $(this);
$row.children('td').each(function () {
id += $(this).text();
});
Children()只查看元素内容的第一级,因此这是最快的方法。首先,我建议不要在同一操作中多次选择同一元素,每次通过jQuery选择某个元素时,都必须遍历DOM才能找到它。 例如,查找一次#searchBarText并重复使用它,如下所示:
var $searchBarText = $('#searchBarText');
$row = $(this);
$row.children('td').each(function () {
id += $(this).text();
});
至于你提到的代码块,我将这样做:
var $searchBarText = $('#searchBarText');
$row = $(this);
$row.children('td').each(function () {
id += $(this).text();
});
Children()只查看元素内容的第一级,因此这是最快的方式。我添加了您的两项更改,我相信它们确实有助于提高效率,因此,感谢您的帮助。然而,错误似乎仍然存在。一点调试发现,只有当我一次删除整个文本(即选择所有退格)时,才会发生这种情况。但是,当我在每个字符后缓慢按backspace时,错误不会发生。我正在使用文本字段中的onkeyup调用此函数。我添加了您的两个更改,我相信它们确实有助于提高效率,因此感谢您的支持。然而,错误似乎仍然存在。一点调试发现,只有当我一次删除整个文本(即选择所有退格)时,才会发生这种情况。但是,当我在每个字符后缓慢按backspace时,错误不会发生。我正在使用文本字段中的onkeyup调用此函数