如何隐藏“未找到图像” IE和Chrome上的图标使用CSS [英] how to hide "image not found" icon on IE and chrome using CSS
本文介绍了如何隐藏“未找到图像” IE和Chrome上的图标使用CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网页上有一些图片。
I have some images on my page.
默认情况下,如果指定的图片不可用,则会在Chrome和IE上显示损坏的图片指示符。
By default if a given image is not available, then the broken image indicator is shown on Chrome and IE.
我想要不显示,但在这种情况下的替代文本。
I want nothing to be shown but the alternative text in this case. Is there any way to handle it using CSS.
推荐答案
使用javascript
using javascript
<img src="broken.png" onerror="this.style.display='none'"/>
编辑:添加可处理所有图片的小型snipet。
edit: added small snipet that will handle all images.
$("img").error(function(){$(this).hide();});
示例: http: //jsfiddle.net/Va2Wd/
这篇关于如何隐藏“未找到图像” IE和Chrome上的图标使用CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文