如何判断图片地址是否失效
时间:2020-10-20 15:11:13|栏目:JavaScript代码|点击: 次
<html>
<body>
<IMG src="http://www.google.com/logos/Logo_25wht.gif" alt="图片来源正常"></p>
<IMG src="abc.gif">
</body>
</html>
<script language="javascript">
var AllImages=document.getElementsByTagName("IMG");
for(i=0;i<AllImages.length;i++)
{
var img=AllImages[i];
img.onerror=function()
{
this.src="http://www.yaosansi.com/blog/logo.gif";
this.alt="图片来源错误";
}
}
</script>
<body>
<IMG src="http://www.google.com/logos/Logo_25wht.gif" alt="图片来源正常"></p>
<IMG src="abc.gif">
</body>
</html>
<script language="javascript">
var AllImages=document.getElementsByTagName("IMG");
for(i=0;i<AllImages.length;i++)
{
var img=AllImages[i];
img.onerror=function()
{
this.src="http://www.yaosansi.com/blog/logo.gif";
this.alt="图片来源错误";
}
}
</script>