An error has occurred in the JavaScript Console. F

2019-08-13 23:44发布

问题:

HI I am getting this peculiar information in my console of IE 11 ,

An error has occurred in the JavaScript Console. Functionality might be affected.

this information is showed when I run a for loop to form the list of elements in ul tag for 4000 times, I put the i in console but it stops at 999 and this message is shown below.

      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>";

            }

I dont know why its not running more than 999. Thank you.

回答1:

I received this same error recently, while testing some JavaScript code in IE 11.

The solution for me was to reduce the number of times that the console.log prints from within my FOR loop.

For example, printing to the console only if the index is divisible by 20.

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

(Link to jsFiddle page can also be found here.)



回答2:

Does element_list contain more than 999 values? Check the length of element_list



回答3:

var names = items.map(function(item) {
return item['name'];
});

I was getting the same error but managed to bypass it by using the .map function.

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