问题描述
我知道 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
()返回一个NodeList
-
querySelectorAll
()按文档顺序返回NodeList
-
getElementsByTagName
()返回HTMLCollection
-
getElementsByClassName
()返回HTMLCollection
getElementsByName
(DOM Level-2-HTML) returns aNodeList
querySelectorAll
(Selectors API) returns aNodeList
"in document order"getElementsByTagName
(DOM) returns aHTMLCollection
getElementsByClassName
(DOM) returns aHTMLCollection
和都被指定为
HTMLCollection
s and NodeList
s 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选择方法的文档顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!