DOM选择方法的文档顺序 [英] document order for DOM selection method

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

问题描述

我知道 getElementsByTagName 返回的实时NodeList会保留元素的文档顺序。

I know that live NodeList returned by getElementsByTagName preserves the document order of elements.

是否为真? getElementsdByClassName getElementsByName querySelectorAll methods?

Is it true for getElementsdByClassName, getElementsByName and querySelectorAll methods?

这些方法是否也保留了文档顺序?

does these method also preserve the document order?

任何DOM / HTML5 W3C标准链接都将受到赞赏。

Any DOM/HTML5 W3C standard link would be appreciated.

推荐答案

是的。所有这些都是文档顺序/树顺序。

Yes. All of them are in document order / tree order.


  • getElementsByName DOM Level-2-HTML )返回一个 NodeList

  • querySelectorAll 选择器API )按文档顺序返回 NodeList

  • getElementsByTagName DOM )返回 HTMLCollection

  • getElementsByClassName DOM )返回 HTMLCollection

  • getElementsByName (DOM Level-2-HTML) returns a NodeList
  • querySelectorAll (Selectors API) returns a NodeList "in document order"
  • getElementsByTagName (DOM) returns a HTMLCollection
  • getElementsByClassName (DOM) returns a HTMLCollection

HTMLCollection s NodeList s 都被指定为

HTMLCollections and NodeLists are both specified to have


元素是以树顺序排序。

当通过indizes访问它们时。 NodeList是否存在并不重要(当然,实际文档顺序可能与静态NodeList中保留的文档顺序相反)。

when those are accessed via indizes. It does not really matter whether the NodeList is live or not (though of course the actual document order could change in contrast to the one preserved in the static NodeList).

这篇关于DOM选择方法的文档顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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