From d192fb918b0e2aa8869de6dcc59de8464b6e879a Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Fri, 11 Dec 2020 18:59:39 -0500 Subject: dump 2020-12-11 --- .../web/api/parentnode/queryselectorall/index.html | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'files/zh-cn/web/api') diff --git a/files/zh-cn/web/api/parentnode/queryselectorall/index.html b/files/zh-cn/web/api/parentnode/queryselectorall/index.html index 1664ec5559..2f7bc72f71 100644 --- a/files/zh-cn/web/api/parentnode/queryselectorall/index.html +++ b/files/zh-cn/web/api/parentnode/queryselectorall/index.html @@ -16,7 +16,7 @@ translation_of: Web/API/ParentNode/querySelectorAll

The {{domxref("ParentNode")}} mixin defines the querySelectorAll() method 返回一个 {{domxref("NodeList")}} 表示元素的列表,把当前的元素作为根与指定的选择器组相匹配。

-

If you need only a single result, consider the {{domxref("ParentNode.querySelector", "querySelector()")}} method instead.

+

如果你只需要一个结果,可以考虑使用{{domxref("ParentNode.querySelector", "querySelector()")}}方法来代替。

Note: This method is implemented as {{domxref("Element.querySelectorAll()")}}, {{domxref("Document.querySelectorAll()")}}, and {{domxref("DocumentFragment.querySelectorAll()")}}

@@ -24,7 +24,7 @@ translation_of: Web/API/ParentNode/querySelectorAll

语法

-
elementList = parentNode.querySelectorAll(selectors);
+
elementList = parentNode.querySelectorAll(selectors);
 

参数

@@ -41,10 +41,10 @@ translation_of: Web/API/ParentNode/querySelectorAll

返回值

-

A non-live {{domxref("NodeList")}} containing one {{domxref("Element")}} object for each descendant node that matches at least one of the specified selectors.

+

一个不存活的 {{domxref("NodeList")}} ,每个子节点拥有一个 {{domxref("Element")}} 对象,其中每个子节点至少与一个选择器相匹配。

-

Note: If the specified selectors include a CSS pseudo-element, the returned list is always empty.

+

Note: 如果指定的 selectors 包含CSS pseudo-element,那么返回的列表始终为空。

Exceptions

@@ -58,24 +58,24 @@ translation_of: Web/API/ParentNode/querySelectorAll

To obtain a {{domxref("NodeList")}} of all of the {{HTMLElement("p")}} elements in the document:

-
var matches = document.querySelectorAll("p");
+
var matches = document.querySelectorAll("p");

这个例子返回了所有 class 为 "note" 或者 "alert" 的 div 元素的一个列表:

-
var matches = document.querySelectorAll("div.note, div.alert");
+
var matches = document.querySelectorAll("div.note, div.alert");

Here, we get a list of <p> elements whose immediate parent element is a {{domxref("div")}} with the class "highlighted" and which are located inside a container whose ID is "test".

-
var container = document.querySelector("#test");
+
var container = document.querySelector("#test");
 var matches = container.querySelectorAll("div.highlighted > p");

This example uses an attribute selector to return a list of the {{domxref("iframe")}} elements in the document that contain an attribute named "data-src":

-
var matches = document.querySelectorAll("iframe[data-src]");
+
var matches = document.querySelectorAll("iframe[data-src]");

Here, an attribute selector is used to return a list of the list items contained within a list whose ID is "userlist" which have a "data-active" attribute whose value is "1":

-
var container = document.querySelector("#userlist");
+
var container = document.querySelector("#userlist");
 var matches = container.querySelectorAll("li[data-active=1]");

User notes

@@ -86,7 +86,7 @@ var matches = container.querySelectorAll("li[data-active=1]");

Consider this HTML, with its three nested {{HTMLElement("div")}} blocks.

-
<div class="outer">
+
<div class="outer">
   <div class="select">
     <div class="inner">
     </div>
@@ -95,7 +95,7 @@ var matches = container.querySelectorAll("li[data-active=1]");

JavaScript

-
var select = document.querySelector('.select');
+
var select = document.querySelector('.select');
 var inner = select.querySelectorAll('.outer .inner');
 inner.length; // 1, not 0!
 
@@ -104,7 +104,7 @@ inner.length; // 1, not 0!

The {{cssxref(":scope")}} pseudo-class restores the expected behavior, only matching selectors on descendants of the base element:

-
var select = document.querySelector('.select');
+
var select = document.querySelector('.select');
 var inner = select.querySelectorAll(':scope .outer .inner');
 inner.length; // 0
-- cgit v1.2.3-54-g00ecf