【问题标题】:What is the difference between a HTMLCollection and a NodeList in DOM? [duplicate]DOM 中的 HTMLCollection 和 NodeList 有什么区别? [复制]
【发布时间】:2013-03-26 00:38:56
【问题描述】:

我尝试了我的 Google-fu,但似乎找不到该问题的任何好的答案。请帮忙。

编辑: 好的,所以我找到了 this 博客文章。所以它们来自不同的 DOM 级别,但除此之外并没有多说......

【问题讨论】:

    标签: dom nodelist htmlcollection


    【解决方案1】:

    如您所说,NodeList 定义在 DOM-Level-3-Core 中,HTMLCollection 定义在 DOM-Level-2-HTML 中。

    他们的接口是:

    interface HTMLCollection {
      readonly attribute unsigned long   length;
      Node               item(in unsigned long index);
      Node               namedItem(in DOMString name);
    };
    
    interface NodeList {
      Node               item(in unsigned long index);
      readonly attribute unsigned long   length;
    };
    

    所以 NodeListHTMLCollection 的继承者,以更通用的形式(对于 xml)。

    猜你喜欢
    • 2011-09-18
    • 2012-11-02
    • 1970-01-01
    • 2015-11-23
    • 2013-02-13
    • 2011-04-26
    • 2016-09-24
    • 1970-01-01
    相关资源
    最近更新 更多