欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

html img标签 图片路径错误时显示默认图片方法

程序员文章站 2022-07-08 11:55:59
...
方法一:
<div style="width:125px; height:90px; border:1px solid red; ">
<img src="errorSrc.gif" width="125" height="90"  onerror="this.src='http://cms.gdzjdaily.com.cn/img/emp2.gif'"/>
</div>

方法二:(新闻网这种做法)
<div style="width:125px; height:90px; border:1px solid red; background-image: url(http://cms.gdzjdaily.com.cn/img/emp2.gif); background-repeat: no-repeat; background-position: center center; background-color:#efefef;">
<img src=" errorSrc.gif " width="125" height="90"/>
</div>
相关标签: html img 图片