2013-08-02 24 views
-1

如果在圖片標籤中圖片url在裏面,並且如果沒有img標籤不會顯示,是否可以使用jQuery進行檢查?現在jQuery如果在img標籤中沒有url,那麼img標籤應該被刪除

HTML:

<div id="slide"> 
    <img src="http://www.url.com/.jpg" alt="" /> 
    <img src="http://www.url.com/.jpg" alt="" /> 
    <img src="" alt="" /> - here is no img url so this one must be deleted 
</div> 

我怎樣才能做到這一點?

回答

2

目標圖像與空源,並且刪除它們:

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

filter()方法:

$('#slide img').filter(function() { 
    return ! $.trim(this.getAttribute('src')).length; 
}).remove(); 
+0

Thnx隊友這工作很好! – Maanstraat

1

嘗試這樣

$("img").each(function(){ 
    if($(this).attr("src") == "") { 
      $(this).remove(); 
     } 
}); 
1

作品:

$('#slide').find('img[src=""]').remove();