起因,寫了兩個html頁面,body中只有div塊,將div個數從1百加到1千后在瀏覽器中調試顯示加載時間DOMContentLoaded:50ms左右(兩者區(qū)別不大),加到1萬后,頁面1顯示500ms左右,頁面2顯示100ms左右。求解:在可預見的情況下,直接寫好html元素和用js插入html元素在各方面的對比。頁面1: <!DOCTYPE html>
<html>
<body>
<div>hello world</div>
..........
.......
....
<div>hello world</div>
</body>
</html>頁面2: <!DOCTYPE html>
<html>
<body>
<div id="div1">hello world</div>
</body>
<script>
for(var i=0;i<9999;i++){
var div = document.createElement("div");
var node = document.createTextNode("hello world");
div.appendChild(node);
var element =document.getElementById('div1');
element.appendChild(div);
}
</script>
</html>
添加回答
舉報
0/150
提交
取消