Javascript 删除带有空src的图像标记
我的html中的图像标记具有空的src属性。 这会导致不同浏览器中出现错误。 我想动态删除所有src为空的图像标记 Html: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="">
<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()
})
更正它将在加载文档后加载。更正它将在加载文档后加载。