如何判断图片地址是否失效
发布时间:2016-12-30 来源:查字典编辑
摘要:varAllImages=document.getElementsByTagName("IMG");for(i=0;i
<html>
<body>
<IMGsrc="http://www.google.com/logos/Logo_25wht.gif"alt="图片来源正常"></p>
<IMGsrc="abc.gif">
</body>
</html>
<scriptlanguage="javascript">
varAllImages=document.getElementsByTagName("IMG");
for(i=0;i<AllImages.length;i++)
{
varimg=AllImages[i];
img.onerror=function()
{
this.src="http://www.yaosansi.com/blog/logo.gif";
this.alt="图片来源错误";
}
}
</script>