网页中图片路径错误时显示默认图片方法

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

 

posted @ 2013-10-29 11:05  Mr.Thanks  阅读(330)  评论(1编辑  收藏  举报