且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测破碎的图像并用另一个替换?

更新时间:2022-04-17 21:34:47

是的,这可以使用onerror事件:

Yes this is possible using onerror event:

<img src="your_image_source" onerror="this.src='/path/to/local/file'">

如果图片不存在,而不是显示X,则会在您的图片中显示默认图片本地文件夹

If the image does not exist, instead of displaying the X, this will show the default image in your local folder