如果找不到图像,如何防止显示图像占位符? [英] How to prevent the display of image placeholder if the image is not found?

查看:91
本文介绍了如果找不到图像,如何防止显示图像占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果找不到图像,是否可以不显示图像占位符?我已经通过自动Feed加载了图片,对于某些商品,图片在那里,但是对于某些商品则没有.因此,如果图像不存在,我想显示一个自定义占位符.

Is there a way to not display the image placeholder if the image was not found? I've got images loaded by automatic feed, and for some items images are there, but for some there are not. So, if the image is not there, I would like to display a custom placeholder.

推荐答案

我找到了答案这段代码很棒!

function onImgErrorSmall(source)
{
source.src = "/images/no-image-100px.gif";
// disable onerror to prevent endless loop
source.onerror = "";
return true;
}

然后这样称呼它:

<img src="/images/19013_small.jpg" alt="" onerror="onImgErrorSmall(this)" />

这篇关于如果找不到图像,如何防止显示图像占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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