简体   繁体   English

如何循环DocumentFragment的孩子?

[英]How to loop through DocumentFragment's children?

How can I loop through DocumentFragment childNodes ? 如何循环DocumentFragment childNodes I've tried doing the following: 我尝试过以下方法:

console.log(result.childNodes);
console.log(result.childNodes.length);

But length seems to be 0 even if I can see the actual child nodes in firebug, like: 但是即使我可以在firebug中看到实际的子节点,长度似乎也是0,如:

[div#tiptip_arrow]
0

Update: 更新:

http://jsfiddle.net/ve5hf/ This is not exactly what I'm doing, but demonstrates the problem: when I have a look in Firebug console, I see that the fragment has child nodes, but console.log(result.childNodes); http://jsfiddle.net/ve5hf/这不是我正在做的,但是演示了这个问题:当我查看Firebug控制台时,我看到该片段有子节点,但是console.log(result.childNodes); yields [] for some reason. 因某种原因收益率[] Why is that? 这是为什么?

var o = document.createDocumentFragment();
o.appendChild(document.createElement('div'));
var childNodes = o.childNodes;
for (var i = 0, len = childNodes.length; i < len; i++) {
  console.log(childNodes[i].tagName);
}

.length does work. .length确实有效。

We need more specifics. 我们需要更多具体细节。 How do you create the document fragment? 你如何创建文档片段? What browser? 什么浏览器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM