2014-07-15 41 views
0

我試圖找出如何隱藏我的一個側面的導航按鈕,如果沒有內容加載垂直標籤內容PHP數組

(每節1-4每個標籤的部分變化身體部分,目前有三個標籤加載)

我正在使用一個PHP數組來加載我的網頁的這個部分的所有內容。

下面是我的一些代碼示例(精簡盡我所能) Js Fiddle

我首先想到的是「如果」做的,和「其他」聲明,我從另一個例子嘗試從這裏,但我仍然需要找出一種方法來關閉按鈕的CSS只是不確定如何解決這個問題!

任何幫助表示讚賞,請注意我是新手到PHP!

另外這裏的部分內容加載與陣列多麼正義,幫助直觀的鏈接:

http://imgur.com/WRkXzv3 Screenshot of Array Content

這裏是一個真實被列入到PHP文件我的數組的一個片段

// #Hips# 
$injuries['Hips'] = array(
    "BodyPartLink" => "Hips", 
    "TitlePage" => "Hips Injuries & Education", 
    "IntroTxt" => "Hips Intro Text Here", 
    "SectionTab1" => "", 
    "SectionTab2" => "Hip Condition #2", 
    "SectionTab3" => "Hip Condition #3", 
    "ContentSection" => "Hips Dummy Text Here For Large Text Section" 
); 

// #Hips Section Contents TAB 1 # 
$Tab1SectionContents['Hips'] = array(
    "Definition" => "<span class='edu-sub-category-txt-bold'>Definition:</span>Lower Back Information coming soon! ", 
    "Function" => "<span class='edu-sub-category-txt-bold'>Function:</span>Information coming soon!", 
    "Mechanism" => "Mechanism of Injury ", 
    "MechanismTxt" => "Information coming soon!", 
    "Sign-Symptoms" => "Signs & Symptoms ", 
    "Sign-SymptomsTxt" => "Information coming soon!", 
    "Etiology" => "Etiology ", 
    "EtiologyTxt" => "Information coming soon!", 
    "Pero-Treatment" => "Pero Treatment ", 
    "Pero-TreatmentTxt" => "Information coming soon!", 
    "Other-Treatment" => "Other Treatment ", 
    "Other-TreatmentTxt" => "Information coming soon!" 
); 

// #Hips Section Contents TAB 2 # 
$Tab2SectionContents['Hips'] = array(
    "Definition" => "<span class='edu-sub-category-txt-bold'>Definition:</span>Lower Back -- Phasellus erat sem, molestie vitae turpis et, vehicula facilisis dolor. Mauris ut iaculis eros,  in auctor nibh. In eget nisl tristique elit varius semper. ", 
    "Function" => "<span class='edu-sub-category-txt-bold'>Function:</span> Function -- molestie vitae turpis et, vehicula facilisis dolor. Mauris ut iaculis eros,", 
    "Mechanism" => "Mechanism of Injury ", 
    "MechanismTxt" => "Text for Mechanism", 
    "Sign-Symptoms" => "Signs & Symptoms ", 
    "Sign-SymptomsTxt" => "Signs & Symptoms ", 
    "Etiology" => "Etiology ", 
    "EtiologyTxt" => "Etiology ", 
    "Pero-Treatment" => "Pero Treatment ", 
    "Pero-TreatmentTxt" => "Pero Treatment ", 
    "Other-Treatment" => "Other Treatment ", 
    "Other-TreatmentTxt" => "Other Treatment " 
); 

// #Hips Section Contents TAB 3 # 
$Tab3SectionContents['Hips'] = array(
    "Definition" => "<span class='edu-sub-category-txt-bold'>Definition:</span>Lower Back -- Phasellus erat sem, molestie vitae turpis et, vehicula facilisis dolor. Mauris ut iaculis eros,  in auctor nibh. In eget nisl tristique elit varius semper. ", 
    "Function" => "<span class='edu-sub-category-txt-bold'>Function:</span> Function -- molestie vitae turpis et, vehicula facilisis dolor. Mauris ut iaculis eros,", 
    "Mechanism" => "Mechanism of Injury ", 
    "MechanismTxt" => "Text for Mechanism", 
    "Sign-Symptoms" => "Signs & Symptoms ", 
    "Sign-SymptomsTxt" => "Signs & Symptoms ", 
    "Etiology" => "Etiology ", 
    "EtiologyTxt" => "Etiology ", 
    "Pero-Treatment" => "Pero Treatment ", 
    "Pero-TreatmentTxt" => "Pero Treatment ", 
    "Other-Treatment" => "Other Treatment ", 
    "Other-TreatmentTxt" => "Other Treatment " 
); // ## END HIPS ## 

回答

0

你可以用Javascript來做到這一點。檢查與您的標籤關聯的div是否爲空 - 因此沒有數據/內容出現。如果它是空的,請將其移除。

$(function(){ 
    if (!$('.element').html()){ 
     // If the element is empty, remove it 
     $('.element').remove(); 
    } 
}); 
+0

好,謝謝,我會嘗試給一個去 – dimerbox

+0

請註明我的問題是正確的,如果你的作品(和+1吧)。謝謝=) – Ben

+0

哦,好吧,一旦我有機會,我一定會這麼做!非常感謝這個網站! :) – dimerbox