【问题标题】:An error has occurred in the JavaScript Console. Functionality might be affectedJavaScript 控制台中出现错误。功能可能会受到影响
【发布时间】:2015-06-26 05:08:23
【问题描述】:

您好,我在 IE 11 的控制台中收到了这些特殊信息,

JavaScript 控制台发生错误。功能可能 受到影响。

当我运行 for 循环以形成 ul 标记中的元素列表 4000 次时,会显示此信息, 我将 i 放在控制台中,但它在 999 处停止,此消息如下所示。

      for (var i = 0; i < 4000; i++) {
                console.log(i)
                param_html="'"+element_list[i]["sElement"]["#text"].replace('/', '')
+ "','" + element_list[i]["sElementDesc"]["#text"].replace('/', '')+"'";
                html += "<li class='ui-widget-content  addElementandlocation image-" + element_list[i]["iInciLocFlag"]["#text"].replace('/', '') + " onclick=dao.load_location_element_loca(" + param_html + "); module='location2'    id='" + element_list[i]["sElement"]["#text"] + "'><span   class=code>" + element_list[i]["sElement"]["#text"] + "</span><span  class=description>" + element_list[i]["sElementDesc"]["#text"].replace('/', '') + "</span></li>";

            }

我不知道为什么它的运行速度不超过 999。 谢谢。

【问题讨论】:

  • 我现在有同样的问题。你能解决这个问题吗?

标签: javascript jquery performance internet-explorer


【解决方案1】:

我最近在 IE 11 中测试一些 JavaScript 代码时收到了同样的错误。

我的解决方案是减少从我的 FOR 循环中打印 console.log 的次数。

例如,仅当索引可被 20 整除时才打印到控制台。

for (var i = 0, j = 4000; i < j; i++) {
  if (i % 20 == 0) {
    console.log(i);
  }
}

(jsFiddle页面的链接也可以找到here。)

【讨论】:

    【解决方案2】:

    element_list 是否包含超过 999 个值?检查 element_list 的长度

    【讨论】:

    • 是的,它有超过 999 个,实际上它有 4197 个
    【解决方案3】:
    var names = items.map(function(item) {
    return item['name'];
    });
    

    我遇到了同样的错误,但设法通过使用 .map 函数绕过它。

    http://api.jquery.com/map/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      • 2018-07-12
      • 2016-10-24
      • 2021-05-31
      相关资源
      最近更新 更多