我的功能如下所示。考虑高性能,我该如何避免在html中的循环结构中添加文本?请指教。非常感谢。如何避免在循环中将元素附加到DOM
function createDiv (array) {
var i;
var target = document.getElementById("container");
for(i = 0; i < array.length; i++) {
target.appendChild("<div>" + array[i] + "</div>");
}
}
使用像Handlebars模板引擎:http://handlebarsjs.com/ – dana
此外这个问题可能更适合[CodeReview](http://codereview.stackexchange.com/) –