我想通过PHP改变两个选项卡的类,但我被困在基本条件。下面是我的代码:
CSS.myinfo { background-color:black }
.deactive { background-color : white }
HTML
<li class="myinfo <?=$deact?>">
<a href="myaccount.php?<?=$qry_str?>" >My Info</a>
</li>
<li class="myinfo <?=$deact?>">
<a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>
</li>
我需要的是
如果
$_GET['mycontacts']
是活动的
那么My Info链接的类应该是deactive
否则我的联系人链接应该有deactive
类
我试过了:
if (isset($_GET['mycontacts'])){
$deact ='deactive';
}
但是没有成功。请帮忙写这个条件(我认为一行ternary condition
可以工作)。
试试这个:
<li class="myinfo <?php echo ($_GET['mycontacts'] === 'active' ? 'deactive' : '') ?>">
<a href="myaccount.php?<?=$qry_str?>" >My Info</a>
</li>
<li class="myinfo <?php echo ($_GET['mycontacts'] !== 'active' ? 'deactive' : '') ?>">
<a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>
</li>
顺便说一下,我讨厌php短标签!个人喜好…