Get the App
SLTechnology News&Howtos  ›  Development  › 

How to automatically repair damaged images by jQuery

Shulou Source: shulou.com Published: 2022-06-01 04:51:12 11月12日 Update

Editor to share with you how jQuery automatically repair damaged images, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Automatically repair damaged images

Replacing broken image links one by one is very painful. However, the following simple code can help you:

$('img') .on (' error', function () {if (! $(this) .hasClass ('broken-image')) {$(this) .prop (' src', 'img/broken.png'). AddClass (' broken-image');}})

Even if there are no broken links, adding this piece of code won't cost you anything.

The above is all the contents of the article "how to repair damaged images automatically by jQuery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Images articles code content links help pain not much most loss more knowledge industry information information channels channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Microsoft NVidia macOS