2.1 KiB
2.1 KiB
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
587d774c367417b2b2512a9d | Know When Alt Text Should be Left Blank | 0 | https://scrimba.com/c/cM9P4t2 | 301019 | 知道 Alt 文本何时应该留空 |
Description
img
标签必须有一个alt
属性。在图片已经有了文字说明,或者仅仅为了美化页面的情况下,alt
属性似乎有些多余。
即便如此,我们仍然需要为img
标签添加alt
属性,这时可以把它设为空,例如:
<img src="visualDecoration.jpeg" alt="">
背景图片通常起装饰作用,而且含有 CSS 类,所以屏幕阅读器无法读取。
注意:对于有标题的图片,我们依然需要添加
alt
属性,因为这样有助于搜索引擎记录图片内容。
Instructions
alt
属性(注意:这里img
标签的src
属性提供的链接是无效的,因此页面上可能不会显示图片,不用担心)。
Tests
tests:
- text: '你的<code>img</code>标签应该包含<code>alt</code>属性。'
testString: assert(!($('img').attr('alt') == undefined));
- text: '<code>alt</code>属性对应的值应该为空。'
testString: assert($('img').attr('alt') == '');
Challenge Seed
<h1>Deep Thoughts with Master Camper Cat</h1>
<article>
<h2>Defeating your Foe: the Red Dot is Ours!</h2>
<p>To Come...</p>
</article>
<img src="samuraiSwords.jpeg">
<article>
<h2>Is Chuck Norris a Cat Person?</h2>
<p>To Come...</p>
</article>
Solution
// solution required