使用 settimeout 来防止“停止运行此脚本”在jquery中
我有一个很长的 for 循环来验证表中一次一行的文本框(超过 1000 行):我不断收到“停止运行此脚本”错误。很多网站都提到了setTimeout()函数。但我仍然无法让它工作。这是我的代码:
var numRows = $("#tablex").attr('rows').length;
var errorMsg="";
for (var tbRow = 1; tbRow < numRows - 1; tbRow++) {
var aRecord = $("#tablex tr:eq(" + tbRow + ") td:eq(1)").attr("innerText");
var curECD = $("#tablex tr:eq(" + tbRow + ") td:eq(7)").find(':text').val().trim();
if (curECD != "" && isDate(curECD) == false)
errorMsg += "Date for " + aRecord + " is invalid<br/>";
}
有人可以帮忙吗?谢谢!!!
I have a long for loop to validate textboxes one row at a time in a table(over 1000 rows): i keep getting the "stop running this script" error. Many websites mentioned setTimeout() function. But i still cant get it to work. Here is my code:
var numRows = $("#tablex").attr('rows').length;
var errorMsg="";
for (var tbRow = 1; tbRow < numRows - 1; tbRow++) {
var aRecord = $("#tablex tr:eq(" + tbRow + ") td:eq(1)").attr("innerText");
var curECD = $("#tablex tr:eq(" + tbRow + ") td:eq(7)").find(':text').val().trim();
if (curECD != "" && isDate(curECD) == false)
errorMsg += "Date for " + aRecord + " is invalid<br/>";
}
can anyone help? thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为上面建议的第一个解决方案更好,但我认为您也可以像这样递归地执行。取决于您的要求:
这将调用 validateRow 并传入第一行。 ValidateRow 将在 setTimeout 上调用自身并传入下一行。当它到达末尾时,它将调用您提供的回调函数。
I think the first suggested above solution is better, but you could also do it recursively like this I think. Depends what your requirements are:
This will call validateRow and pass in the first row. ValidateRow will than call itself on a setTimeout and pass in the next row. When it reaches the end it will call a callback function that you supply.
我制作了这个这个小例子来帮助您使用
setTimeout< 枚举块中的列表/代码>。
像这样称呼它:
I made this this little example to help you with enumerating a list in chunks with a
setTimeout
.Call it like this: