久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 querySelectorAll().方法返回的結果是否有序?

Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
本文介紹了使用 querySelectorAll().方法返回的結果是否有序?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試制作一個適用于多個頁面的 js 代碼.我正在嘗試使用 querySelectorAll() 從 DOM 中獲取元素.

I'm trying to make a js code that works with multiple pages. I'm trying to use querySelectorAll() to obtain the elements form the DOM.

我需要訂購元素.為此,我可以使用 xPath 或選擇器(我更喜歡使用選擇器,但 xPath 也可以).問題是:
querySelectorAll() 返回的 NodeList 中的元素是否按照標簽在 HTML 中出現的順序排列?

I need the elements to be ordered. In order to do that I may use xPath or selectors (I'd prefer to use selectors but xPath is also ok). The problem is:
Are the elements in the NodeList returned by querySelectorAll() ordered against the order that the tags appear in the HTML?

注意:我想添加標簽:querySelectorAll

Note: I'd like to add the tag: querySelectorAll

推薦答案

返回的節點列表是有序的.快速測試證明了這一點:

The returned node list is ordered. A quick test proved it:

document.querySelectorAll("body, head")[0]; //Returned [object HTMLHeadElement]

顯然,<head> 標簽出現在 HTML 文檔中的 <body> 之前.NodeList 的第一個元素也是 <head> 元素,即使選擇器在 `head 之前顯示 body.

Obviously, the <head> tag appears before <body> in a HTML document. The first element of the NodeList is also a <head> element, even if the selector shows body before `head.

來自 http://www.w3.org/TR/selectors-api/#queryselectorall:

NodeSelector 接口上的 querySelectorAll() 方法必須,當調用,返回一個包含所有匹配元素的 NodeList節點子樹中的節點,按文檔順序.如果沒有此類節點,該方法必須返回一個空的 NodeList.

The querySelectorAll() method on the NodeSelector interface must, when invoked, return a NodeList containing all of the matching Element nodes within the node’s subtrees, in document order. If there are no such nodes, the method must return an empty NodeList.

這篇關于使用 querySelectorAll().方法返回的結果是否有序?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
TestCafe - How to check if a web element exists or does not exist without failing the test?(TestCafe - 如何在不通過測試的情況下檢查 Web 元素是否存在?)
主站蜘蛛池模板: 一区免费视频 | 一区二区日韩 | 欧美亚洲在线观看 | 成人在线播放视频 | 亚洲精品免费观看 | 97色婷婷 | 精品在线观看视频 | 成人激情视频在线观看 | 天天草夜夜草 | 日韩精品一区二区在线 | 野外(巨肉高h) | 中文字幕在线观看一区二区三区 | 欧美黄色三级视频 | 日韩小视频 | 色综合久久天天综合网 | 天天做天天爱 | 日韩视频二区 | 久草视频在线播放 | 国产午夜精品一区二区三区视频 | 一色桃子av| av黄色在线 | 中文字幕欧美激情 | 天天干夜夜撸 | 婷婷99| 久久国产精品一区二区三区 | 黄色一级大片在线免费看产 | 国产在线视频一区二区 | 中文字幕在线免费视频 | 九九热在线视频观看 | 一级片免费观看 | 欧美精品福利 | 国产免费一区二区三区免费视频 | 久久伊人av | 福利视频网址 | 天天爽夜夜爽夜夜爽精品视频 | 在线看片a | 亚洲专区在线 | 色综合av | 九九国产精品视频 | 狠狠婷婷| 人人干人人草 |