DocumentFragment: querySelectorAll() 方法
DocumentFragment.querySelectorAll() 方法使用深度優先的文件節點前序遍歷,返回 NodeList,其中包含 DocumentFragment 中與指定選擇器組匹配的所有元素。
如果引數中指定的選擇器無效,則會引發一個具有 SYNTAX_ERR 值的 DOMException。
語法
js
querySelectorAll(selectors)
引數
選擇器 (selectors)-
一個包含一個或多個以逗號分隔的 CSS 選擇器的字串。
返回值
一個非即時的 NodeList,包含每個至少匹配指定選擇器中一個選擇器的元素的一個 Element 物件,如果沒有匹配項,則為空 NodeList。
示例
此示例返回 DocumentFragment 中所有類為 note 或 alert 的 div 元素列表。
js
const matches = documentFrag.querySelectorAll("div.note, div.alert");
規範
| 規範 |
|---|
| DOM # ref-for-dom-parentnode-queryselectorall① |
瀏覽器相容性
載入中…
另見
- 它所屬的
DocumentFragment介面。