Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS在类中隐藏损坏的图像_Javascript_Jquery - Fatal编程技术网

Javascript JS在类中隐藏损坏的图像

Javascript JS在类中隐藏损坏的图像,javascript,jquery,Javascript,Jquery,我知道如何隐藏图像,如果它们如下所示 <img src=""......> 不平凡 试一试 $(function(){$(“[data bg]”)。每个(function(){const$parent=$(this).最近的(.lx gallery”)const img=new Image();img.onerror=function(){$parent.hide();}img.src=$(this).data(“bg”)})都工作得非常好。谢谢你。你可以只需c

我知道如何隐藏图像,如果它们如下所示

<img src=""......>
不平凡

试一试


$(function(){$(“[data bg]”)。每个(function(){const$parent=$(this).最近的(.lx gallery”)const img=new Image();img.onerror=function(){$parent.hide();}img.src=$(this).data(“bg”)})都工作得非常好。
谢谢你。你可以只需
const$this=$(this)
然后
$this.hide()
如果要用背景隐藏div
<div class="lx-g3-f" >
  <div class="lx-gallery" data-bg="image_url" alt="alt text" referrerpolicy="no-referrer" title="something title">
  <div class="lx-gallery-title" >
    <h3><a href='something_img_url' referrerpolicy="no-referrer">click here!</a></h3>
  </div>
</div>              
$("img").on("error", function() {
    $(this).closest('.lx-g3-f').hide();
});
$(function() {
  $("[data-bg]").each(function() {
    const $parent = $(this).closest(".lx-g3-f")
    const img = new Image();
    img.onerror=function() {
      $parent.hide();
    }
    img.src=$(this).data("bg")
  })
})