2018-10-10 18:03:03 -04:00
---
id: bad87fee1348bd9aedf08827
2020-12-16 00:37:30 -07:00
title: 创建一个无序列表
2018-10-10 18:03:03 -04:00
challengeType: 0
2019-12-26 20:05:59 +08:00
videoUrl: 'https://scrimba.com/p/pVMPUv/cDKVPuv'
forumTopicId: 16814
2021-01-13 03:31:00 +01:00
dashedName: create-a-bulleted-unordered-list
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-01-08 11:20:48 -08:00
HTML 有一个特定的元素用于创建<dfn>无序列表</dfn>。
2020-12-16 00:37:30 -07:00
2021-01-20 18:58:05 -08:00
无序列表以 `<ul>` 开始,中间包含一个或多个 `<li>` 元素, 最后以 `</ul>` 结束。
2020-12-16 00:37:30 -07:00
例如:
2019-12-26 20:05:59 +08:00
```html
<ul>
2021-01-21 10:07:18 -08:00
<li>milk</li>
<li>cheese</li>
2019-12-26 20:05:59 +08:00
</ul>
```
2021-02-06 04:42:36 +00:00
会创建一个要点列表,包括 `milk` 和 `cheese` 。
2019-12-26 20:05:59 +08:00
2020-12-16 00:37:30 -07:00
# --instructions--
2021-01-08 11:20:48 -08:00
请删除页面底部的两个 `p` 元素,然后在底部创建一个无序列表,其中包含你认为猫咪最喜欢的三件东西。
2020-12-16 00:37:30 -07:00
# --hints--
2021-01-08 11:20:48 -08:00
应存在一个 `ul` 无序列表。
2020-12-16 00:37:30 -07:00
```js
assert($('ul').length > 0);
2018-10-10 18:03:03 -04:00
```
2021-01-08 11:20:48 -08:00
应在 `ul` 无序列表中添加三个 `li` 条目。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert($('ul li').length > 2);
```
2018-10-10 18:03:03 -04:00
2021-01-08 11:20:48 -08:00
确保 `ul` 无序列表有结束标签。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
code.match(/<\/ul>/gi) &&
code.match(/<ul/gi) &&
code.match(/<\/ul>/gi).length === code.match(/<ul/gi).length
);
2018-10-10 18:03:03 -04:00
```
2021-01-08 11:20:48 -08:00
确保每个 `li` 条目都有结束标签。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
code.match(/<\/li>/gi) &&
code.match(/<li[\s>]/gi) &&
code.match(/<\/li>/gi).length === code.match(/<li[\s>]/gi).length
);
```
2021-01-08 11:20:48 -08:00
每个 `li` 元素不应只包含空字符串或只包含空格。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert($('ul li').filter((_, item) => !$(item).text().trim()).length === 0);
```
2018-10-10 18:03:03 -04:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```html
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
2021-09-22 08:34:59 -07:00
<a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>
2021-01-13 03:31:00 +01:00
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>
```
2020-12-16 00:37:30 -07:00
# --solutions--
2018-10-10 18:03:03 -04:00
2021-01-13 03:31:00 +01:00
```html
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
2021-09-22 08:34:59 -07:00
<a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>
2021-01-13 03:31:00 +01:00
<ul>
<li>milk</li>
<li>mice</li>
<li>catnip</li>
</ul>
</main>
```