创建文档碎片

文档碎片可以他高DOM操作性能(主要针对插入:一次性插入大量元素)

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head>
 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 4 <title>无标题文档</title>
 5 <script type="text/javascript">
 6 window.onload=function (){
 7     var oUl=document.getElementById('ul1');
 8     var oLi=null;
 9     var oFrag=document.createDocumentFragment();//创建文档碎片
10     var i=0;
11     
12     for(i=0;i<100;i++){
13         oLi=document.createElement('li');
14         //oUl.appendChild(oLi);
15         oFrag.appendChild(oLi);
16     }
17     
18     oUl.appendChild(oFrag);
19 };
20 </script>
21 </head>
22 
23 <body>
24 <ul id="ul1">
25 </ul>
26 </body>
27 </html>
原文地址:https://www.cnblogs.com/wxydigua/p/3240758.html