创建一个DOM NodeList [英] Creating a DOM NodeList

查看:110
本文介绍了创建一个DOM NodeList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆