DocumentFragment.querySelectorAll()

DocumentFragment.queryselectorall()方法返回NodeList中的元素DocumentFragment(使用文档节点的深度优先顺序遍历)匹配指定的选择器组。

如果参数中指定的选择器无效,则会引发一个带SYNTAX_ERR值的DOMException

注意:这个API的定义被移动到ParentNode接口。

语法

elementList = documentframgment.querySelectorAll(selectors);

参数

selectors
是一个DOMString包含一个或多个用逗号分隔的CSS选择器。

示例

此示例返回DocumentFragment中所有div元素的列表,其中包含一个类“note”或“alert”:

var matches = documentfrag.querySelectorAll("div.note, div.alert");

规范

Specification Status Comment
Selectors API Level 1
DocumentFragment.querySelectorAll
Obsolete Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
querySelectorAllChrome Full support 1Edge Full support 12Firefox Full support 3.5IE Full support 8Opera Full support 10Safari Full support 3.2WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3.2Samsung Internet Android Full support Yes

Legend

Full support  
Full support

参阅