如何能高效的批量生成DIV
批量生成500~1000个DIV
我用了CreateElement,但是效率不是很理想
有更高效的办法吗?
------解决方案--------------------用文档碎片方法createDocumentFragment,然后用appendchild合并到文档中
------解决方案--------------------这个应该是最高效的...
谁有更高效的PK一下...
<body>
<script type= "text/javascript ">
/* <![CDATA[*/
var Count = 0;
var Len = 1000;
var StartDate = new Date();
var Span = document.createElement( "span ");
var Ar = [];
for(var i=0; i <Len; i++)
{
Ar.push( " <div> ");
Ar.push(i);
Ar.push( " <br/> ");
Ar.push( " </div> ");
}
Span.innerHTML = Ar.join( " ");
document.body.appendChild(Span);
var EndDate = new Date();
defaultStatus = EndDate - StartDate;
/*]]*/
</script>
------解决方案--------------------以下代码无实用价值,博君一笑而已
肯定不慢于上面的,
<body>
<script type= "text/javascript ">
/* <![CDATA[*/
var Count = 0;
var Len = 1000;
var StartDate = new Date();
var Span = document.createElement( "span ");
var Ar = [];
Ar[0]= " <div> "+0;
for(var i=1; i <Len-1; i++)
{
Ar.push(i);
}
Ar[Len-1]=Len+ " </div> ";
Span.innerHTML = Ar.join( " <br/> </div> <div> ");
document.body.appendChild(Span);
var EndDate = new Date();
defaultStatus = EndDate - StartDate;
/*]]*/
</script>
回到楼主的主题,
大批量对量用innerHTML
大量字符串想加用array的join