【发布时间】:2015-05-21 01:08:07
【问题描述】:
我正在尝试动态创建 1500 行,每行有 4 个单元格。在 Internet Explorer 11 中,它花费了太多时间 - 36 秒。我使用了浏览器的分析器,发现insertCell 函数本身花费了 30 秒(总共,对于所有 1500×4 调用)。
如何提高建表功能的性能? insertCell 有什么替代品吗?
function createRow(tableObj, newRowIndex, rowData, rowId) {
var newCell, colID, newRow, i;
newRow = tableObj.insertRow(newRowIndex);
newRow.id = tableObj.id.replace(/DATATABLE/, "R" + rowId);
colID = newRow.id + "C";
for (i in rowData.Cells) { // rowData.Cells = 4
if (rowData.Cells.hasOwnProperty(i)) {
newCell = newRow.insertCell(i);
newCell.id = colID + i;
newCell.className = "c" + rowData.Cells[i].id;
newCell.innerHTML = rowData.Cells[i].data;
}
}
}
【问题讨论】:
-
在插入页面之前尝试构建整个 dom?
标签: javascript html dom internet-explorer-11