2018-10-10 18:03:03 -04:00
---
id: bad87fee1348bd9aedf08804
2020-12-16 00:37:30 -07:00
title: 给 HTML 添加注释
2018-10-10 18:03:03 -04:00
challengeType: 0
2019-12-26 20:05:59 +08:00
videoUrl: 'https://scrimba.com/p/pVMPUv/cGyGbca'
forumTopicId: 16782
2021-01-13 03:31:00 +01:00
dashedName: comment-out-html
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-01-08 11:20:48 -08:00
记住:注释的开始标记是 `<!--` ,结束标记是 `-->` 。
2020-12-16 00:37:30 -07:00
2021-01-08 11:20:48 -08:00
现在你需要在 `h2` 元素开始前终止注释。
2020-12-16 00:37:30 -07:00
# --instructions--
2021-01-20 18:58:05 -08:00
注释掉 `h1` 元素和 `p` 元素,保留 `h2` 元素。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-01-08 11:20:48 -08:00
应注释掉 `h1` 元素,这样它就从网页上消失了。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert($('h1').length === 0);
```
2021-01-08 11:20:48 -08:00
`h2` 元素应保持原样,这样网页上还能看到它。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert($('h2').length > 0);
```
2018-10-10 18:03:03 -04:00
2021-01-08 11:20:48 -08:00
应注释掉 `p` 元素,这样它就从网页上消失了。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert($('p').length === 0);
2018-10-10 18:03:03 -04:00
```
2021-01-08 11:20:48 -08:00
每一个注释都应以 `-->` 结尾。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/[^fc]-->/g).length > 1);
```
2021-01-08 11:20:48 -08:00
不要更改 `h1` 元素、`h2` 元素、`p` 元素的顺序。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(
code.match(/< ([a-z0-9]){1,2}>/g)[0] === '< h1 > ' & &
code.match(/< ([a-z0-9]){1,2}>/g)[1] === '< h2 > ' & &
code.match(/< ([a-z0-9]){1,2}>/g)[2] === '< p > '
);
```
2018-10-10 18:03:03 -04:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```html
<!--
< h1 > Hello World< / h1 >
< h2 > CatPhotoApp< / h2 >
< 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 >
-->
```
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
<!-- <h1>Hello World</h1> -->
< h2 > CatPhotoApp< / h2 >
<!-- <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> -->
```