2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf08820
|
|
|
|
challengeType: 0
|
2019-12-26 20:05:59 +08:00
|
|
|
videoUrl: 'https://scrimba.com/p/pVMPUv/cRdBnUr'
|
|
|
|
forumTopicId: 18327
|
2020-10-01 17:54:21 +02:00
|
|
|
title: 给图片添加链接
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2019-12-26 20:05:59 +08:00
|
|
|
<section id='description'>
|
|
|
|
你可以通过把元素嵌套进 <code>a</code> 里使其变成一个链接。
|
|
|
|
把你的图片嵌套进 <code>a</code>。举例如下:
|
|
|
|
<code><a href="#"><img src="http://cdn.freecodecamp.cn/running-cats.jpg" alt="三只萌萌的小猫"></a></code>
|
|
|
|
把 <code>a</code> 的<code>href</code>属性设置为<code>#</code>,就可以创建固定链接。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2019-12-26 20:05:59 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
把现存的图片嵌套进 <code>a</code> 中。
|
|
|
|
当鼠标悬停在图片上时,鼠标的光标如果从箭头指针变成手形指针,那么此时图片就是一个链接了。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2019-12-26 20:05:59 +08:00
|
|
|
- text: '把现存的图片嵌套进 <code>a</code> 中。'
|
|
|
|
testString: assert($("a").children("img").length > 0);
|
|
|
|
- text: '<code>a</code> 的<code>href</code>属性应为<code>#</code>。'
|
|
|
|
testString: assert(new RegExp("#").test($("a").children("img").parent().attr("href")));
|
|
|
|
- text: '确保每个 <code>a</code> 都有结束标记。'
|
|
|
|
testString: assert(code.match(/<\/a>/g) && code.match(/<a/g) && code.match(/<\/a>/g).length === code.match(/<a/g).length);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<h2>CatPhotoApp</h2>
|
|
|
|
<main>
|
2019-12-26 20:05:59 +08:00
|
|
|
<p>点击查看更多<a href="#">猫咪图片</a>。</p>
|
|
|
|
|
|
|
|
<img src="https://bit.ly/fcc-relaxing-cat" alt="一只仰卧着的萌猫">
|
|
|
|
|
|
|
|
<p>在大家心目中,猫是慵懒和可爱的化身,它可以睡饱了再起来吃饭,可以逗趣小耗子,可以卖得了萌,使得了坏,这样百变的小怪兽就集结在一只宠物上,怎能不惹人怜爱。</p>
|
|
|
|
<p>养猫有的时候,就是介于爱与恨之间,当你钦羡别人萌宠这么可爱的时候,你一定没有想过,猫咪会到处掉毛,甚至会屯老鼠,啃鞋子,用爪子爬门,你不理它,它就挠你,你要对它发脾气,它会比你更来劲。所以,猫咪慎入,没有一定的准备,切勿随便去侍养动物。它们一旦认定你了,你就是它们的主人,如果你抛弃它们,它们必定心中重创。</p>
|
2018-10-10 18:03:03 -04:00
|
|
|
</main>
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
</section>
|
2019-12-26 20:05:59 +08:00
|
|
|
|