2014-02-27 28 views
0

即時通訊顯示每個數組的結果,其中我需要隱藏一個按鈕只有在列表中的特定項目, 我試過它使用if語句,但它的隱藏按鈕的整個列表項,請指教我呢?如何顯示:每個數組中沒有數據行?

這裏我已經把代碼的地方。這將隱藏即使ID不等於83

<div class="jd-items-button-details"> 
<?php if(($item->categories_id)==83) { ?> 
    <style type="text/css"> 
     .jd-button-details {display:none !important} 
    </style> 
<?php 
} else { 
    echo "test2"; 
} 
echo $item->categories_id; 
?> 
<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="jd-button-details"') ?> 

回答

1

您可以使用類似全按鈕:

<div class="jd-items-button-details" <?= $item->categories_id == 83 ? 'style="display: none"' : ''?>>

+0

Thanks @MrZebra:它的工作 – fdz

1

即使寫一次,你的CSS樣式將被應用到各個環節與.jd-button-details類。相反,你應該該類conditionnaly適用於您的按鈕:

<style type="text/css"> 
    .jd-button-details 
    {display: none!important;} 
</style> 

<div class="jd-items-button-details"> 

<?php 
if(($item->categories_id)==83){ 
    $class = 'jd-button-details'; 
} 
else { 
    $class = ''; 
} 
echo $item->categories_id; 
?> 
<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="<?php echo $class; ?>"') ?> 

或者更短:

<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="'.(($item->categories_id)==83 ? "jd-button-details" : "").'"') ?> 
0

最容易做的是:不要使用標籤<styles>,因爲它將應用到你整個HTML區域顯示。使用內聯樣式:

<div class="jd-items-button-details"> 
<?php if(($item->categories_id) !== 83){ ?> 
    <button>this is button</button> 
<?php 
}