2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1348bd9aedf08828
|
|
|
|
|
challengeType: 0
|
2019-12-26 20:05:59 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/p/pVMPUv/cQ3B8TM'
|
|
|
|
|
forumTopicId: 16824
|
2020-10-01 17:54:21 +02:00
|
|
|
|
title: 创建一个有序列表
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-12-26 20:05:59 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
HTML 有一个特定的元素用于创建有序列表<code>ordered lists(缩写 ol)</code>。
|
|
|
|
|
有序列表以<code><ol></code>开始,中间包含一个或多个<code><li></code>元素,最后以<code></ol></code>结尾。
|
|
|
|
|
|
|
|
|
|
例如:
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<ol>
|
|
|
|
|
<li>加菲猫</li>
|
|
|
|
|
<li>哆啦A梦</li>
|
|
|
|
|
</ol>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
将会创建一个包含加菲猫和哆啦A梦的有序列表。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2019-12-26 20:05:59 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
创建一个有序列表,内容是猫咪最讨厌的三件东西,内容可以任意指定。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2019-12-26 20:05:59 +08:00
|
|
|
|
- text: '页面应该有一个无序列表,内容是猫咪最喜欢的三件东西。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert((/Top 3 things cats hate:/i).test($("ol").prev().text()));
|
2019-12-26 20:05:59 +08:00
|
|
|
|
- text: '页面应该有一个有序列表,内容是猫咪最讨厌的三件东西。'
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert((/Things cats love:/i).test($("ul").prev().text()));
|
2019-12-26 20:05:59 +08:00
|
|
|
|
- text: '页面应该只有一个<code>ul</code>元素。'
|
|
|
|
|
testString: assert.equal($("ul").length, 1);
|
|
|
|
|
- text: '页面应该只有一个<code>ol</code>元素。'
|
|
|
|
|
testString: assert.equal($("ol").length, 1);
|
|
|
|
|
- text: '<code>ul</code>无序列表应该包含3个<code>li</code>条目。'
|
|
|
|
|
testString: assert.equal($("ul li").length, 3);
|
|
|
|
|
- text: '<code>ol</code>有序列表应该包含3个<code>li</code>元素。'
|
|
|
|
|
testString: assert.equal($("ol li").length, 3);
|
|
|
|
|
- text: '确保<code>ul</code>无序列表有结束标记。'
|
|
|
|
|
testString: assert(code.match(/<\/ul>/g) && code.match(/<\/ul>/g).length === code.match(/<ul>/g).length);
|
|
|
|
|
- text: '确保<code>ol</code>有序列表有结束标记。'
|
|
|
|
|
testString: assert(code.match(/<\/ol>/g) && code.match(/<\/ol>/g).length === code.match(/<ol>/g).length);
|
|
|
|
|
- text: '确保每个<code>li</code>条目都有结束标记。'
|
|
|
|
|
testString: assert(code.match(/<\/li>/g) && code.match(/<li>/g) && code.match(/<\/li>/g).length === code.match(/<li>/g).length);
|
|
|
|
|
- text: '无序列表里的 <code>li</code> 元素不应该为空。'
|
|
|
|
|
testString: $('ul li').each((i, val) => assert(val.textContent.replace(/\s/g, '')));
|
|
|
|
|
- text: '有序列表里的 <code>li</code> 元素不应该为空。'
|
|
|
|
|
testString: $('ol li').each((i, val) => assert(!!val.textContent.replace(/\s/g, '')));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<h2>CatPhotoApp</h2>
|
|
|
|
|
<main>
|
2019-12-26 20:05:59 +08:00
|
|
|
|
<p>点击查看更多<a href="#">猫咪图片</a>。</p>
|
|
|
|
|
|
|
|
|
|
<a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="一只仰卧着的萌猫"></a>
|
|
|
|
|
|
|
|
|
|
<p>猫咪最喜欢的三件东西:</p>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
<ul>
|
2019-12-26 20:05:59 +08:00
|
|
|
|
<li>猫薄荷</li>
|
|
|
|
|
<li>激光笔</li>
|
|
|
|
|
<li>千层饼</li>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</ul>
|
2019-12-26 20:05:59 +08:00
|
|
|
|
<p>猫咪最讨厌的三件东西:</p>
|
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</main>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
</section>
|
2019-12-26 20:05:59 +08:00
|
|
|
|
|