freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-html-and-html5/create-an-ordered-list.md

3.0 KiB
Raw Blame History

id challengeType videoUrl forumTopicId localeTitle
bad87fee1348bd9aedf08828 0 https://scrimba.com/p/pVMPUv/cQ3B8TM 16824 创建一个有序列表

Description

HTML 有一个特定的元素用于创建有序列表ordered lists缩写 ol。 有序列表以<ol>开始,中间包含一个或多个<li>元素,最后以</ol>结尾。

例如:

<ol>
  <li>加菲猫</li>
  <li>哆啦A梦</li>
</ol>

将会创建一个包含加菲猫和哆啦A梦的有序列表。

Instructions

创建一个有序列表,内容是猫咪最讨厌的三件东西,内容可以任意指定。

Tests

tests:
  - text: '页面应该有一个无序列表,内容是猫咪最喜欢的三件东西。'
    testString: assert((/Top 3 things cats hate:/i).test($("ol").prev().text()));
  - text: '页面应该有一个有序列表,内容是猫咪最讨厌的三件东西。'
    testString: assert((/Things cats love:/i).test($("ul").prev().text()));
  - 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, '')));

Challenge Seed

<h2>CatPhotoApp</h2>
<main>
<p>点击查看更多<a href="#">猫咪图片</a></p>
  
  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="一只仰卧着的萌猫"></a>
  
  <p>猫咪最喜欢的三件东西:</p>
  <ul>
    <li>猫薄荷</li>
    <li>激光笔</li>
    <li>千层饼</li>
  </ul>
  <p>猫咪最讨厌的三件东西:</p>
  
</main>

Solution