2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf08802
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 去除 HTML 的注释
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2019-12-26 12:05:59 +00:00
|
|
|
videoUrl: 'https://scrimba.com/p/pVMPUv/cBmG9T7'
|
|
|
|
forumTopicId: 18329
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2019-12-26 12:05:59 +00:00
|
|
|
注释的作用是给代码添加一些说明,方便团队合作或日后自己查看,但又不影响代码本身。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2019-12-26 12:05:59 +00:00
|
|
|
注释的另一个用途就是在不删除代码的前提下,让代码不起作用。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
在 HTML 中,注释的开始标签是 `<!--`,结束标签是 `-->`。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
现在我们反其道而行之,去掉 `h1` 元素、`h2` 元素、`p` 元素的注释。
|
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
|
|
|
页面上应存在 `h1` 元素。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('h1').length > 0);
|
|
|
|
```
|
|
|
|
|
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
|
|
|
页面上应存在 `p` 元素。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert($('p').length > 0);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
应删除注释的结束标签 `-->`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!$('*:contains("-->")')[1]);
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|