我在 myasp.net MVC Web 应用程序中有以下代码:-
<a href="~/Content/uploads/@(item.ID).png"><img class="thumbnailimag" src="~/Content/uploads/@(item.ID).png" /></a> @Html.ActionLink(item.Name,"Details","DataCenter", new{id = item.ID},null)
以及以下 CSS:
.thumbnailimag {
width:30px;
height:30px;
border:thin blue;
background-image:url("/Content/uploads/virtual-data-center.jpg");
}
But if the image does not exists each bowser will treat it differently . I set a background image but still on IE it will display a “X” over the default image , as follow:-
如果 src 不存在,任何人都可以建议是否有办法显示默认图像?
当然,对于您的图像使用:
<img src="fails/to/load.png" onerror="this.src='path/to/replacement/image.jpg'" />
CSS 中没有解决方案,它需要 JS 应用于每个<img>
标签或顶级处理程序来替换onerror
所有图像的事件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)