测试以查看是否使用JSON值的图像坏/或不存在,并与&QUOT代替;没有照片"图片? [英] Test to see if an image with json value is broken/ or not there and replace with "no-photo" image?

查看:164
本文介绍了测试以查看是否使用JSON值的图像坏/或不存在,并与&QUOT代替;没有照片"图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我和我的团队正在使用后端服务抢JSON数据显示在前端图像。我们有一个JavaScript将显示,当他们是没有价值无photo.png的形象,并显示正常的产品形象时,他们是一个值。


My team and I are using a backend service to grab json data to display images on the frontend. We have a javascript that will display a "no-photo.png" image when their is no value and display the normal product image when their is a value.

问题是,我们会尽快回复值,但图像回来打破,因为他们不是真正那里,我们没有手动删除它们的方式。

The problem is that we will get back values, but the images come back broken because they are not actually there and we have no way of manually removing them.

我的问题是:结果
是他们的一种方式,以确定是否即使图像有值?图像被破

My question is:
Is their a way to determine if the image is broken even if the image has a value?

推荐答案

设置的onerror 回调:

var img = new Image();
img.onerror = function () {
    this.src = 'noimage.jpg';
};
img.src = 'path/from/json/img.jpg';

这篇关于测试以查看是否使用JSON值的图像坏/或不存在,并与&QUOT代替;没有照片"图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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