如何在IE和Chrome中隐藏破碎的图像图标? [英] how to hide broken image icon in IE and chrome?

查看:96
本文介绍了如何在IE和Chrome中隐藏破碎的图像图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部好,



我们在asp.net \ MVV的列表中绑定图像。如果从文件夹中找到图像,它工作正常。但是当我们在文件夹中找不到图像时,它会在IE / chrome中显示X以显示未找到的图像。



我们将alt文本应用为字符串为空,以便它不会在浏览器上显示任何损坏的图像或X.这在Mozila上工作正常,但在IE和Chorme上没有。



有些伙伴可以帮帮我吗?

HI all ,

we are binding images in one of the list in asp.net \MVC. it works fine if image is found from the folder. but when we dont found images in the folder it shows X in the IE / chrome to show that image not found.

we apply alt text as string empty so that it wont show any broken image or X on browser. this works fine on Mozila but not on IE and Chorme.

can some buddy help me please ?

推荐答案

显然它是某种Webkit bug。



您可以使用 onerror 属性隐藏图像(或替换它)

Apparently it's some kind of Webkit bug.

You can use the onerror property to hide the image (or replace it)
function onError(img) {
    delete img.onerror;
    // Change the url
    //img.src = 'images/noload.jpg';
    
    // or just hide it (jQuery)
    //jQuery(img).hide();
}




<img src="http://dev.null" onerror="onError(this)">


也许您可以试试这个链接



jquery-javascript-to-replace-broken-images [ ^ ]
Probably you may try this link

jquery-javascript-to-replace-broken-images[^]


这篇关于如何在IE和Chrome中隐藏破碎的图像图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆