<html>
<body>
<IMGsrc=" http://www.chcode.net/images/chcode.gif"alt="图片来源正常"></p>
<IMGsrc="abc.gif">
</body>
</html>
<scriptlanguage="javascript">
varAllImages=document.getElementssByTagName("IMG");
for(i=0;i<AllImages.length;i++)
{
varimg=AllImages[i];
img.onerror=function()
{
this.src=" http://www.chcode.net/images/chcode.gif";
this.alt="图片来源错误";
}
}
</script>
<body>
<IMGsrc=" http://www.chcode.net/images/chcode.gif"alt="图片来源正常"></p>
<IMGsrc="abc.gif">
</body>
</html>
<scriptlanguage="javascript">
varAllImages=document.getElementssByTagName("IMG");
for(i=0;i<AllImages.length;i++)
{
varimg=AllImages[i];
img.onerror=function()
{
this.src=" http://www.chcode.net/images/chcode.gif";
this.alt="图片来源错误";
}
}
</script>
本文介绍了一种在网页中使用JavaScript来确保图片加载稳定的方案。当原始图片加载失败时,该脚本会自动将图片源替换为备用资源,从而提高用户体验。
1897

被折叠的 条评论
为什么被折叠?



