如何在chrome中显示图像的替代文字

Ach*_*ius 70 html google-chrome

除非调整图像的宽度,否则包含无效源的图像会在Firefox中显示替代文本,但不会显示在chrome中.

  <img height="90" width="90"
    src="http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif"
    alt="Image Not Found"/>
Run Code Online (Sandbox Code Playgroud)

如何显示图像的替代文字?

Pri*_*ner 86

如果我是对的,这是webkit中的一个错误(根据这个).我不确定你能做多少,对不起的答案很抱歉.

但是,您可以使用一种工作方式.如果您将title属性添加到图像(例如title="Image Not Found")它将起作用.

  • 你可能需要增加它的高度和宽度:http://jsfiddle.net/AAyz4/ (4认同)

rah*_*hul 24

您可以使用该title属性.

<img height="90" width="90"
src="http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif"
alt="Google Images" title="Google Images" />
Run Code Online (Sandbox Code Playgroud)


Ale*_*xis 5

是的,这是 webkit 中的一个问题,也在 chromium 中报告:http://code.google.com/p/chromium/issues/detail ?id=773 自 2008 年以来就存在......但仍未修复!

我正在使用 javacsript 和 jQuery 来解决这个问题。

function showAlt(){$(this).replaceWith(this.alt)};
function addShowAlt(selector){$(selector).error(showAlt).attr("src", $(selector).src)};
addShowAlt("img");
Run Code Online (Sandbox Code Playgroud)

如果您只想要一张图片:

addShowAlt("#myImgID");
Run Code Online (Sandbox Code Playgroud)