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>
<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>