2018-10-10 18:03:03 -04:00
---
id: bad87fed1348bd9aedf08833
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/ckK73C9'
forumTopicId: 17559
2021-01-13 03:31:00 +01:00
dashedName: delete-html-elements
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
手机屏幕的空间是有限的。
2018-10-10 18:03:03 -04:00
2021-01-08 11:20:48 -08:00
让我们删除不必要的元素,开始设计我们的 CatPhotoApp。
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
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
# --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(!code.match(/< h1 > /gi) && !code.match(/< \/h1 > /gi));
```
2018-10-10 18:03:03 -04:00
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(code.match(/< h2 > [\w\W]*< \/h2 > /gi));
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(code.match(/< p > [\w\W]*< \/p > /gi));
```
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
< 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 >
```