如果条件为真,如何隐藏标题的div

时间:2018-06-07 09:11:38

标签: php

我只是想隐藏div"仪表板可用的仪表板块列表。"如果$ check == 0

<div id="heading" style="display:block">List of dashboard blocks that are available to your dashboard.</div>

if ($check == 0) {
            ?>
            <tr>
                <td> <div class="col-lg-12 col-md-12">All blocks are already added into the dashboard</div></td>
            </tr>
            <?php }
        ?>

2 个答案:

答案 0 :(得分:1)

您缺少PHP的打开和关闭标记。

我还建议使用我在下面使用的短if语句,这样你就不会在模板中追逐那个“}”,但是你可以看到它清楚地标记为“endif”

<div id="heading" style="display:block">List of dashboard blocks that are available to your dashboard.</div>
<?php if ($check == 0) : ?>
    <tr>
        <td> 
            <div class="col-lg-12 col-md-12">All blocks are already added into the dashboard</div>
        </td>
    </tr>
<?php endif; ?>

编辑后我认为你只想隐藏第一行,在这种情况下,如果是echo语句,你可以用速记内联检查

<div id="heading" style="display:<?= $check == 0 ? 'none':  'block' ?>">List of dashboard blocks that are available to your dashboard.</div>

答案 1 :(得分:0)

试试这个,

 <?php 
     if ($check == 0) { 
         $hideDiv = 'style="display:none"';
     }else{ 
         $hideDiv = 'style="display:block"';
     }
 ?>
<div id="heading" <?php echo $hideDiv; ?> >List of dashboard blocks that are available to your dashboard.</div>
<tr>
    <td> 
       <div class="col-lg-12 col-md-12">All blocks are already added into the dashboard</div>
    </td>
</tr>