如果/当加载页面时出现图片问题,我正在尝试更改img
标签的src
标签。我似乎从Internet Explorer 9中获得了一些随机行为,其中一些图像正确显示替换后的图像,一些图像上有红色十字。如果我在浏览器中调试,我会被告知ImgError()
未被定义。它在代码中有明确的定义,显然是有效的。这是为什么发生?用Javascript更改图片src
<div class="PhotoBorder"><img alt="" onerror="imgError(this)"
src="./images/services/69_Staffmember.jpg" /></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(window).load(function() {
$('.RowWrapper').each(function() {
var TotalWidth = 0;
$(this).find('.StaffMember').each(function() {
TotalWidth = TotalWidth + $(this).outerWidth(true);
});
this.style.width = TotalWidth + "px";
});
});
function imgError(img)
{
img.setAttribute("src","./images/services/49_ImgMissing.jpg");
img.removeAttribute("onerror");
}
</script>
其中IE版本 –
TotalWidth.toString()+“px”; –
对不起,IE版本9。 –