创建 DOM 节点列表

发布于 2024-08-12 05:21:02 字数 216 浏览 9 评论 0原文

我正在实现 ECMA-357 附件 A 中描述的所有可选 E4X 功能,但在实现 domNodeList(§A.1.2 和 §A.2.2)时遇到问题。我如何创建自己的 NodeList 对象?

即使我创建一个新的 XMLDocument 并将节点的每个 domNode() 表示形式附加到 XMLList 中,我仍然不知道如何创建一个包含所有内容的 NodeList,因为注释和处理指令通常被排除在外。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-08-19 05:21:02

我发现我可以使用文档片段的 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 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文