Creating a DOM NodeList

杀马特。学长 韩版系。学妹 提交于 2019-12-29 05:59:09

问题


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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/1776769/creating-a-dom-nodelist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!