簡體   English   中英

如何顯示:每個數組中沒有數據行?

[英]How to display:none of data row in a for each array?

我顯示每個數組的結果列表,我需要隱藏列表中的特定項目的按鈕,我嘗試使用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"') ?>

您可以使用以下內容:

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

即使編寫一次,您的css樣式也將應用於.jd-button-details類的每個鏈接。 相反,您應該條件地將此類應用於您的按鈕:

<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" : "").'"') ?>

最容易做的是:不要使用標簽<styles>因為它將應用於你顯示的整個html區域。 使用內聯樣式:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM