--- id: bad87fee1348bd9aedf08812 title: Add Images to Your Website challengeType: 0 guideUrl: 'https://chinese.freecodecamp.org/guide/certificates/add-images-to-your-website' videoUrl: '' localeTitle: 添加图片到您的网站 --- ## Description
您可以使用img元素将图像添加到网站,并使用src属性指向特定图像的URL。这方面的一个例子是: <img src="https://www.your-image-source.com/your-image.jpg">请注意, img元素是自动关闭的。所有img元素都必须具有alt属性。 alt属性中的文本用于屏幕阅读器以提高可访问性,并在图像无法加载时显示。注意:如果图像纯粹是装饰性的,则使用空的alt属性是最佳做法。理想情况下,除非需要,否则alt属性不应包含特殊字符。让我们在上面的img示例中添加一个alt属性: <img src="https://www.your-image-source.com/your-image.jpg" alt="Author standing on a beach with two thumbs up.">
## Instructions
让我们尝试将图像添加到我们的网站:在h2元素之前插入img标记。现在设置src属性,使其指向此URL: https://bit.ly/fcc-relaxing-cathttps://bit.ly/fcc-relaxing-cat最后不要忘记为您的图像添加alt文字。
## Tests
```yml tests: - text: 您的页面应该有一个图像元素。 testString: 'assert($("img").length > 0, "Your page should have an image element.");' - text: 您的图像应具有指向小猫图像的src属性。 testString: 'assert(new RegExp("\/\/bit.ly\/fcc-relaxing-cat|\/\/s3.amazonaws.com\/freecodecamp\/relaxing-cat.jpg", "gi").test($("img").attr("src")), "Your image should have a src attribute that points to the kitten image.");' - text: 您的图片元素必须具有alt属性。 testString: 'assert(code.match(/alt\s*?=\s*?(\"|\").*(\"|\")/), "Your image element must have an alt attribute.");' ```
## Challenge Seed
```html

CatPhotoApp

Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.

Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.

```
## Solution
```js // solution required ```