替代图像而不是替代文本

Alternative image instead of alternative text

本文关键字:文本 图像      更新时间:2023-09-26

如何显示替代图像而不是替代文本?

像这样:

<img src="image_i_want_to_display.png" alt="not_found_image.png"/>

在 Javascript 中处理 onerror 事件,将src设置为新映像,并希望您不要递归。

理论上:

<object data="image_i_want_to_display.png">
    <object data="not_found_image.png">
        Still some alternative text because 
        some people turn images off and some
        people can't see
    </object>
</object>

在实践中,上次我尝试浏览器支持很差,但那是几年前的事了。

你几乎肯定会确保你没有试图将人们指向不存在的东西。

好吧,我想的是将替代图像设置为背景

img {
    background: url('alternative-image.png') no-repeat;
}