freeCodeCamp/curriculum/challenges/chinese/04-data-visualization/data-visualization-with-d3/select-a-group-of-elements-...

69 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
id: 587d7fa6367417b2b2512bc3
title: Select a Group of Elements with D3
required:
- src: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js'
challengeType: 6
videoUrl: ''
localeTitle: 使用D3选择一组元素
---
## Description
<section id="description"> D3还有<code>selectAll()</code>方法来选择一组元素。它返回文档中与输入字符串匹配的所有项目的HTML节点数组。这是一个选择文档中所有锚标记的示例 <code>const anchors = d3.selectAll(&quot;a&quot;);</code><code>select()</code>方法一样, <code>selectAll()</code>支持方法链接,您可以将其与其他方法一起使用。 </section>
## Instructions
<section id="instructions">选择文档中的所有<code>li</code>标签,并通过链接<code>.text()</code>方法将其文本更改为“list item”。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 页面上应该有3个<code>li</code>元素每个元素中的文本应该是“list item”。大写和间距应完全匹配。
testString: 'assert($("li").text().match(/list item/g).length == 3, "There should be 3 <code>li</code> elements on the page, and the text in each one should say "list item". Capitalization and spacing should match exactly.");'
- text: 您的代码应该访问<code>d3</code>对象。
testString: 'assert(code.match(/d3/g), "Your code should access the <code>d3</code> object.");'
- text: 您的代码应该使用<code>selectAll</code>方法。
testString: 'assert(code.match(/\.selectAll/g), "Your code should use the <code>selectAll</code> method.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
```html
<body>
<ul>
<li>Example</li>
<li>Example</li>
<li>Example</li>
</ul>
<script>
// Add your code below this line
// Add your code above this line
</script>
</body>
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>