2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d7788367417b2b2512aa2
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 使用 nav 元素使屏幕阅读器更容易导航
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2020-02-11 09:06:41 +00:00
|
|
|
videoUrl: 'https://scrimba.com/c/czVwWSv'
|
|
|
|
forumTopicId: 301024
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: make-screen-reader-navigation-easier-with-the-nav-landmark
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`nav` 也是一个具有语义化特性的 HTML5 标签,它可以使屏幕阅读器快速识别出页面中的导航信息。 它用于呈现页面中的主导航链接。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
对于在多个页面底部出现的站点链接,我们不需要使用 `nav` 标签。 我们将会在下个挑战中学习 `footer` 标签的使用。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Camper Cat 在他的忍者训练页面顶端放置了多个导航链接,但这些链接都写在了 `div` 中。 请将 `div` 标签更改为 `nav` 标签,以提升页面的可访问性。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
应存在一个 `nav` 标签。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('nav').length == 1);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`nav` 标签应包含 `ul` 标签及其列表项。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('nav').children('ul').length == 1);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
不应存在 `div` 标签。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('div').length == 0);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
确保 `nav` 标签是闭合的。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(/<\/nav>/g) &&
|
|
|
|
code.match(/<\/nav>/g).length === code.match(/<nav>/g).length
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-02-11 09:06:41 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<body>
|
|
|
|
<header>
|
|
|
|
<h1>Training with Camper Cat</h1>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#stealth">Stealth & Agility</a></li>
|
|
|
|
<li><a href="#combat">Combat</a></li>
|
|
|
|
<li><a href="#weapons">Weapons</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</header>
|
|
|
|
<main>
|
|
|
|
<section id="stealth">
|
|
|
|
<h2>Stealth & Agility Training</h2>
|
|
|
|
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
|
|
|
|
<article><h3>No training is NP-complete without parkour</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="combat">
|
|
|
|
<h2>Combat Training</h2>
|
|
|
|
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
|
|
|
|
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="weapons">
|
|
|
|
<h2>Weapons Training</h2>
|
|
|
|
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
|
|
|
|
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<body>
|
|
|
|
<header>
|
|
|
|
<h1>Training with Camper Cat</h1>
|
|
|
|
|
|
|
|
<nav>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#stealth">Stealth & Agility</a></li>
|
|
|
|
<li><a href="#combat">Combat</a></li>
|
|
|
|
<li><a href="#weapons">Weapons</a></li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</header>
|
|
|
|
<main>
|
|
|
|
<section id="stealth">
|
|
|
|
<h2>Stealth & Agility Training</h2>
|
|
|
|
<article><h3>Climb foliage quickly using a minimum spanning tree approach</h3></article>
|
|
|
|
<article><h3>No training is NP-complete without parkour</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="combat">
|
|
|
|
<h2>Combat Training</h2>
|
|
|
|
<article><h3>Dispatch multiple enemies with multithreaded tactics</h3></article>
|
|
|
|
<article><h3>Goodbye world: 5 proven ways to knock out an opponent</h3></article>
|
|
|
|
</section>
|
|
|
|
<section id="weapons">
|
|
|
|
<h2>Weapons Training</h2>
|
|
|
|
<article><h3>Swords: the best tool to literally divide and conquer</h3></article>
|
|
|
|
<article><h3>Breadth-first or depth-first in multi-weapon training?</h3></article>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
```
|