在javascript中检测破碎图像的方法? [英] Way to detect broken images in javascript?
本文介绍了在javascript中检测破碎图像的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够检测图像是否损坏,如果图像链接断开,则替换为默认图像。我知道我可以使用图像代理执行此操作,但希望能够使用javascript动态执行此操作。
I need to be able to detect if an image is broken and replace with a default image if the image link is broken. I know i could do this with an image proxy, but was hoping to do it on the fly with javascript.
推荐答案
我相信它是 img
元素的 onerror
事件。 onerror = function(){}
虽然我从未使用过它。
I believe it's the onerror
event of the img
element. onerror=function(){}
though i've never used it.
这篇关于在javascript中检测破碎图像的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文