2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf0887a
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 用 h2 元素代表副标题
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2019-12-26 12:05:59 +00:00
|
|
|
videoUrl: 'https://scrimba.com/p/pVMPUv/cE8Gqf3'
|
|
|
|
forumTopicId: 18196
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: headline-with-the-h2-element
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
在接下来的几节课里,我们将会一步一步地制作一个展示猫咪图片的 HTML5 app。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
这节课中,我们将会为页面引入作为第二级标题的 `h2` 元素。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
这些元素用来告诉浏览器网站的结构是什么样子。 `h1` 元素通常被用作主标题,`h2` 元素通常被用作副标题, 还有 `h3`、`h4`、`h5`、`h6` 元素,它们分别用作不同级别的标题。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
在内容为 "Hello World" 的 `h1` 元素下面创建一个 `h2` 元素,其内容为 “CatPhotoApp”。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
应创建一个 `h2` 元素。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('h2').length > 0);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`h2` 元素应该有结束标签。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(/<\/h2>/g) &&
|
|
|
|
code.match(/<\/h2>/g).length === code.match(/<h2>/g).length
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`h2` 元素的内容应为:`CatPhotoApp`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.isTrue(/cat(\s)?photo(\s)?app/gi.test($('h2').text()));
|
|
|
|
```
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`h1` 元素的内容应为:`Hello World`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert.isTrue(/hello(\s)+world/gi.test($('h1').text()));
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
`h1` 元素应出现在 `h2` 元素之前。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(code.match(/<h1>\s*?.*?\s*?<\/h1>\s*<h2>\s*?.*?\s*?<\/h2>/gi));
|
|
|
|
```
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<h1>Hello World</h1>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<h1>Hello World</h1>
|
|
|
|
<h2>CatPhotoApp</h2>
|
|
|
|
```
|