自动替换损坏的图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动替换损坏的图像相关的知识,希望对你有一定的参考价值。

There are 2 jQuery snippets, both replace broken images with one of your choosing, the difference is that one is "safe" and the other is "persistent". The safe one will quick working, so if your doing something that dynamically changed images on a page it'll only work for the first broken image. The persistent one will keep working, but if your missing image image is missing it'll cause a overflow error.
  1. // Safe Snippet
  2. $("img").error(function () {
  3. $(this).unbind("error").attr("src", "missing_image.gif");
  4. });
  5.  
  6. // Persistent Snipper
  7. $("img").error(function () {
  8. $(this).attr("src", "missing_image.gif");
  9. });

以上是关于自动替换损坏的图像的主要内容,如果未能解决你的问题,请参考以下文章

收藏|分享前端开发常用代码片段

关于js----------------分享前端开发常用代码片段

jquery - 加载图像时替换损坏的图像图标

jQuery/JavaScript 替换损坏的图像

Camera2 API预览方面已损坏

无法替换图像视图,用于来自相机或画廊的图像(它不起作用)