问题描述
我正在实施ECMA-357附件A中描述的所有可选的E4X功能,并且我在执行domNodeList(§A.1.2和§A.2.2)时遇到困难。我如何创建自己的NodeList对象?即使我创建了一个新的XMLDocument,并附加了XMLList中节点的每个domNode()表示,我还是不看看我如何创建一个包含所有内容的NodeList,通常排除注释和处理指令。
我想到可以使用一个文档片段的childNodes属性来创建一个NodeList。这是我的解决方案:
XML.prototype.function :: domNodeList = function(){
var fragment = document .createDocumentFragment(),
len = this.length(),
i = 0; $;
for(; i< len; i ++){
fragment.appendChild(this [i] .domNode());
}
return fragment.childNodes;
}
I'm implementing all of the optional E4X features described in ECMA-357 Annex A and I'm having trouble implementing domNodeList (§A.1.2 and §A.2.2). How would I create my own NodeList object?
Even if I create a new XMLDocument and append every domNode() representation of the nodes in an XMLList, I still don't see how I could create a NodeList containing everything as comments and processing instructions are usually excluded.
I figured out that I could use the childNodes attribute of a document fragment to create a NodeList. This was my solution:
XML.prototype.function::domNodeList = function () {
var fragment = document.createDocumentFragment(),
len = this.length(),
i = 0;
for (; i < len; i++) {
fragment.appendChild(this[i].domNode());
}
return fragment.childNodes;
}
这篇关于创建一个DOM NodeList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!