首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“多余的alt属性。屏幕阅读器已经将`img`标记声明为图像。”代码错误

“多余的alt属性。屏幕阅读器已经将`img`标记声明为图像。”代码错误
EN

Stack Overflow用户
提问于 2021-05-08 22:11:10
回答 2查看 1.6K关注 0票数 0

我在我的React js文件中输入了<img src= {'https://robohash.org/${id}?size=300x300'}alt="photo" />,在我保存了该文件之后,我在GitBash上得到了一条错误消息,

Redundant alt attribute. Screen-readers already announce 'img' tags as an image. You don’t need to use the words 'image', 'photo,' or 'picture' (or any specified custom words) in the alt prop jsx-a11y/img-redundant-alt

然后我从代码中删除了alt,我得到的错误消息是,

img elements must have an alt prop, either with meaningful text, or an empty string for decorative images jsx-a11y/alt-text

我如何解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-05-08 22:22:44

我试过这个方法,它起作用了:

<input type="image" img src = {'https://robohash.org/${id}?size=300x300'} alt="photo" />

(我使用的是,而不是url的单引号)

票数 0
EN

Stack Overflow用户

发布于 2021-07-08 03:35:03

https://robohash.org/${id}?size=300x300'}alt="something“/>

“一些东西”不同于单词“照片”和“图像”(或任何指定的自定义单词)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67448468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档