是否可以在JavaScript中使用Document Fragment在JavaScript中创建嵌套元素?
我想使用DocumentFragment创建一个可重复使用的HTML块。这个想法是为现有数组中的每个对象创建并填充类似于下面的HTML代码的块。我不担心填充内部HTML,现在我只想建立一个嵌套的层次结构。
<div class="container">
<div class="titleABC">
<h2 class="abc"></h2>
<h2 class="efg"></h2>
<h2 class="xyz"></h2>
...
...
...
...
</div>
</div>
我已经将我正在处理的代码添加到 js fiddle 。
在文档片段中,我无法获得多个元素,并且想知道这是否可能。或者,如果有一种更好的方法来实现这一目标,则将朝着正确的方向发展。
最终,我希望能够添加像... 我的JS小提琴中的第16、17、18、19行,并在将其添加到数组中就具有一个代码块。
预先感谢您浪费时间来帮助我解决我的胡说八道。
I would like to create a reuseable html block using documentFragment. The idea is to create and fill a block of html code similar to below, for every object in an existing array. I'm not worried about filling the inner html yet, for now I just want to build a nested hierarchy.
<div class="container">
<div class="titleABC">
<h2 class="abc"></h2>
<h2 class="efg"></h2>
<h2 class="xyz"></h2>
...
...
...
...
</div>
</div>
I've add the code I was working on to a js Fiddle.
I could not get more than one element to work in the document Fragment and was wondering if this is possible. Or if there is a better way to accomplish this, a steer in the right direction would be appreciated.
Ultimately I want to be able to add code like...
line 16, 17, 18, 19 in my js fiddle, and have a code block generated simply from having added it to the array.
Thank you in advance for time you waste helping me with my nonsense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论