Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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 删除带有空src的图像标记_Javascript_Jquery_Image - Fatal编程技术网

Javascript 删除带有空src的图像标记

Javascript 删除带有空src的图像标记,javascript,jquery,image,Javascript,Jquery,Image,我的html中的图像标记具有空的src属性。 这会导致不同浏览器中出现错误。 我想动态删除所有src为空的图像标记 Html: <div class="newsroom-item"> <article> <figure> <a href="/content/NewsRoom/648408.html"> <img src="" alt="" data-blog="" data-list="">

我的html中的图像标记具有空的src属性。 这会导致不同浏览器中出现错误。 我想动态删除所有src为空的图像标记

Html:

<div class="newsroom-item"> 
  <article> 
    <figure> 
      <a href="/content/NewsRoom/648408.html"> 
        <img src="" alt="" data-blog="" data-list=""> 
      </a> 
    </figure> 
  </article> 
</div>
你可以这样做

$('.newsarticle-list #newsarticlelist .newsroom-item figure a img[src='']').remove();
或者如果要使用对象数组

figure.filter(function(){
    if(this.src == '')
       return $(this);
}).remove();
你可以这样做

$('.newsarticle-list #newsarticlelist .newsroom-item figure a img[src='']').remove();
或者如果要使用对象数组

figure.filter(function(){
    if(this.src == '')
       return $(this);
}).remove();
只需使用jQuery删除:

只需使用jQuery删除:

我猜你的意思是:

var figure = $('.newsarticle-list #newsarticlelist .newsroom-item figure a img');

$("img[src='']",figure).remopve();
我猜你的意思是:

var figure = $('.newsarticle-list #newsarticlelist .newsroom-item figure a img');

$("img[src='']",figure).remopve();

您需要在img上使用remove和src=insidefigure标记

代码可能如下所示:

$("figure img[src='']").remove();

您需要在img上使用remove和src=insidefigure标记

代码可能如下所示:

$("figure img[src='']").remove();

如果要删除src属性为空的所有图像标记,可以使用

$('img').each(function(index,element){
     var $el = $(this)
     if($el.attr('src') == '')
          $el.remove()
})

如果要删除src属性为空的所有图像标记,可以使用

$('img').each(function(index,element){
     var $el = $(this)
     if($el.attr('src') == '')
          $el.remove()
})

更正它将在加载文档后加载。更正它将在加载文档后加载。