2012-12-20 26 views
0

我使用標籤DL-DT-DD在網站上列出了商店信息。信息將由服務器生成並放置。如果DT不包含實際值,則刪除DT,DD

<dl class="description-cols"> 

<dt>Shop Name</dt> 
<dd class="divider"> US Master Autos</dd> 

<dt>Toll Free</dt> 
<dd>Not Available</dd> 

<dt>Fax</dt> 
<dd>(305) 345-42324</dd> 

<dt>Email</dt> 
<dd class="divider"> Not Available</dd> 

<dt>Website</dt> 
<dd class="divider"> 
     <a target="_blank" href="http://www.google.com">http://www.google.com</a> 
</dd> 
</dl> 

如果任何行的值是不可用的,我想刪除相應的行(DL & DT)。我想用jQuery或JavaScript來做到這一點。

這是用於測試的jsfiddle。我想去掉免費電話行和電子郵件

+1

你爲什麼不在服務器上那樣做? 好? – Bergi

+0

+1這是個好主意,但是PHP引擎不會聽我說,它會動態地將數據放入標籤中。 –

回答

3

這將幫助:

$('dd:contains("Not Available")').each(function() { 
    $(this).prev().remove(); 
    $(this).remove(); 
});​ 

Updated Fiddle

+0

+1。 +接受。你是rockstar Sid :) –

2

你能做到這樣,

Live Demo

$('dd').each(function(){ 
    if($.trim($(this).text()) == "") 
    { 
     $(this).prev('dt').remove(); 
     $(this).remove();  
    } 
});​ 
+0

是的。你能檢查我添加的小js嗎? –

+0

謝謝@nhahtdh,更正。 – Adil

+0

+1。工程,但我需要一個應該進入DL內,然後循環:) –