图像占位符 [英] Image Placeholder

查看:88
本文介绍了图像占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用背景色定义了图片标签,这样如果没有图片的颜色应该显示,但仍然破碎的图标图标显示如何删除它?

I have defined the image tag with a background color so that if there is no image the color should show but still the broken image icon is showing how to remove that ?

我不想通过添加jquery或任何框架使页面变得庞大,我也无法将任何类型的div添加到图像中,因为该网站几乎完成。

I dont want to make the page bulky by adding jquery or any framework , also i cant add any kind of divs to images because the site is almost done.

找到只有javascript的答案

Found the answer with only javascript

function ImgError(source){
source.src = "/images/noimage.gif";
source.onerror = "";
return true;
}

<img src="someimage.png" onerror="ImgError(this);"/>


推荐答案

您可以使用以下内容隐藏:

you can hide that using following:

<img
  src="my.png"
  onerror="this.style.display='none'"
/>

如果找不到以下图片,您可以显示其他图片:

you can display another image if image not found as follow:

<img src="my.png" onerror="this.src = 'image-not-found.png';" />

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

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