How to speed up the reading of innerHTML in IE8?

后端 未结 5 1263
醉酒成梦
醉酒成梦 2020-12-31 20:45

I am using JQuery with the DataTable plugin, and now I have a big performnce issue on the following line.

aLocalData[jInner] = nTds[j].innerHTML; // jquery.d         


        
5条回答
  •  庸人自扰
    2020-12-31 21:32

    A table with 10 columns and 900 rows will call the innerHTML function for 9000 times. Instead append the innerHTML contents to an array and call innerHTML only once at end of the table.

    Something like:

    var contentArray = ["","","Cell Content","",""];
    container.innerHTML(contentArray.join(""));
    

    This way the innerHTML is called only once in the table build process. If not you could call innerHTML at end of each row bringing down the number of times you call innerHTML to 900.

提交回复
热议问题