[英]If a div tag that includes php is empty, hide the div or display certain text
關於隱藏空div似乎有很多已回答的問題,但是在我嘗試了幾個沒有成功的div后,我問了自己一個問題。 我的頁面上有此部分,以顯示各種情況(在本例中為標題)。
這是顯示標題時的外觀:
沒有標題顯示時的外觀如下:
這是我希望沒有標題顯示時的樣子:
以下是處理此問題所涉及領域的代碼部分,標題是在成員擁有多少點之后收集的,並且是從functions.php中收集的,所以我想要一些可以讀取的內容,即沒有標題可以從函數中收集.php,然后顯示難看的小方塊,而不顯示丑陋的標題,如果有人對此有答案,我會很高興,我已經使用了幾個小時,但沒有成功,我應該說我是一個新手當涉及到php時,甚至當涉及到javascript和jquery時也是如此。
<div id='dumb'>
<div id="assocpoint2">TITEL/S:</div><div id="assocpointprint2">
<? if($gender === 'Mare'){echo find_asda_title($horse);}elseif($gender === 'Stallion'){echo find_asda_title($horse);}elseif($gender === 'Gelding'){echo find_asda_title($horse);} ?>
<? if($gender === 'Mare'){echo find_asea_title($horse);}elseif($gender === 'Stallion'){echo find_asea_title($horse);}elseif($gender === 'Gelding'){echo find_asea_title($horse);} ?>
<? if($gender === 'Mare'){echo find_asja_title($horse);}elseif($gender === 'Stallion'){echo find_asja_title($horse);}elseif($gender === 'Gelding'){echo find_asja_title($horse);} ?>
<? if($gender === 'Mare'){echo find_sisf_title($horse);}elseif($gender === 'Stallion'){echo find_sisf_title($horse);}elseif($gender === 'Gelding'){echo find_sisf_title($horse);} ?>
<? if($gender === 'Mare'){echo find_aspa_title($horse);}elseif($gender === 'Stallion'){echo find_aspa_title($horse);}elseif($gender === 'Gelding'){echo find_aspa_title($horse);} ?>
<? if($gender === 'Mare'){echo find_aswa_title($horse);}elseif($gender === 'Stallion'){echo find_aswa_title($horse);}elseif($gender === 'Gelding'){echo find_aswa_title($horse);} ?>
</div></div>
大部分代碼似乎毫無意義/重復。 為什么不這樣:
$output = find_asda_title($horse) . find_asea_title($horse) . etc...
if (in_array($gender, array('Mare', 'Gelding', 'Stallion')) {
echo $output;
} else {
echo stuff to hide the div
}
如果需要,可以通過CSS處理空div的內容:
只需使用:empty
選擇器將空div作為目標,然后向其添加偽內容即可:
#assocpointprint2:empty:after {
content: "No Title";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.