PHP + HTML - 如果没有,请隐藏按钮

时间:2016-05-03 13:09:14

标签: php jquery html css

这是我的PHP代码:

if ($value = $rec['ip'] <= $cphigh_ip && $cplow_ip <= $value = $rec['ip'])
{
    $cpyes="on ";
    $realString = $value = $rec['ip'];
    $whmLink=$realString[strlen($realString)-1];
}
else
{
    $cpno="not on cPanel";
}

我拥有的HTML表非常简单:

<tr>
    <td>Domain IP:</td>
    <td><?=$ipyes.$ipno.$cpyes.$cpno;?><input type="submit" name="cPanelButton" onClick="window.location.href='https://cp<?=$whmLink; ?>.skycomp.ca:2087'" value="cPanel"></td>
</tr>

有没有办法隐藏else子句中的按钮?甚至在if语句中创建该特定按钮?

2 个答案:

答案 0 :(得分:2)

其中一种方法是设置标志:

$show_button = TRUE;
if ($value = $rec['ip'] <= $cphigh_ip && $cplow_ip <= $value = $rec['ip'])
{
    $cpyes="on ";
    $realString = $value = $rec['ip'];
    $whmLink=$realString[strlen($realString)-1];
} else {
    $show_button = FALSE;
    $cpno="not on cPanel";
}

然后,在您的HTML中,将其包装在if条件中:

<?php if ($show_button) { ?>
    <tr>
        <td>Domain IP:</td>
        <td><?=$ipyes.$ipno.$cpyes.$cpno;?><input type="submit" name="cPanelButton" onClick="window.location.href='https://cp<?=$whmLink; ?>.skycomp.ca:2087'" value="cPanel"></td>
    </tr>
<?php } ?>

这将隐藏整个行。如果您只想隐藏按钮,那么:

<tr>
    <td>Domain IP:</td>
    <td><?php if ($show_button) { ?><?=$ipyes.$ipno.$cpyes.$cpno;?><input type="submit" name="cPanelButton" onClick="window.location.href='https://cp<?=$whmLink; ?>.skycomp.ca:2087'" value="cPanel"><?php } ?></td>
</tr>

答案 1 :(得分:1)

您可以将按钮放入php代码

if ($value = $rec['ip'] <= $cphigh_ip && $cplow_ip <= $value = $rec['ip'])
    {
        $cpyes="on ";
        $realString = $value = $rec['ip'];
        $whmLink=$realString[strlen($realString)-1];
        $ifwhmlink = '<input type="submit" name="cPanelButton"   onClick="window.location.href=\'https://cp'.$whmLink.'.skycomp.ca:2087\'" value="cPanel">';
    }
    else
    {
        $cpno="not on cPanel";
        $ifwhmlink = "";
    }
<tr>
    <td>Domain IP:</td>
    <td><?=$ipyes.$ipno.$cpyes.$cpno.$ifwhmlink;?></td>
</tr>