JavaScript createDocumentFragment() 方法

createDocumentFragment() 方法创建一个文档碎片,与 createElement() 方法的差异如下:

 

var arrText=["1","2","3","4","5","6","7","8","9","10"];
for(var i=0;i<arrText.length;i++)
{
    var op=document.createElement("P");
    var oText=document.createTextNode(arrText[i]);
    op.appendChild(oText);
    document.body.appendChild(op);
}

 

var arrText=["1","2","3","4","5","6","7","8","9","10"];
var oFrag=document.createDocumentFragment();

for(var i=0;i<arrText.length;i++)
{
var op=document.createElement("P");
var oText=document.createTextNode(arrText[i]);
op.appendChild(oText);
oFrag.appendChild(op);

}
document.body.appendChild(oFrag);

 

参考:http://www.cnitblog.com/asfman/articles/32614.html

 

posted @ 2016-10-09 12:30  小车厂  阅读(278)  评论(0编辑  收藏  举报