[英]JavaScript - DOM Manipulation - Is construction a page first then attaching?
New to javascript...and dom manipulation...Let's say I'm using java-script to construct part of a page that has a bunch of sub-elements. javascript和dom操作的新手。假设我正在使用java-script来构建具有一堆子元素的页面的一部分。
<div>my-sub-elements</div>
Should I create a stand-alone-div attach the elements inside then attach the whole thing to the DOM? 我应该创建一个独立的div,然后将整个元素都附加到DOM吗?
Or should I attach the elements one by one to the DOM? 还是应该将元素一个一地附加到DOM?
通常,您不会注意到有什么区别,但是如果确实需要它,那么构造分离的DocumentFragment
并将其附加到一个步骤中,要比将实时DOM树多次弄乱要快得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.