用于设置活动菜单项的 switch 语句
好吧,所以我想我可以这样做,但也许不行。这可能吗?
$url = $_SERVER['REQUEST_URI'];
$active = 'class="bob"';
switch($url){
case('/index.php'):
$active[0] = ' class="active"';
break;
case('/about.php'):
case('/our-customers.php'):
case('/our-partners.php'):
case('/our-clients.php'):
case('/our-standards.php'):
case('/our-awards.php'):
$active[1] = ' class="active"';
break;
case('/solutions.php'):
$active[2] = ' class="active"';
break;
case('/services.php'):
$active[3] = ' class="active"';
break;
case('/sustainability.php'):
case('/what-are-we-doing.php'):
case('/what-can-you-do.php'):
case('/what-we-support.php'):
case('/references.php'):
$active[4] = ' class="active"';
break;
case('/healthcare.php'):
$active[5] = ' class="active"';
break;
case('/blog/'):
$active[6] = ' class="active"';
break;
case('/contact.php'):
$active[7] = ' class="active"';
break;
}
?>
?>
<nav>
<ul class="clearfix">
<li <?php echo $active[0] ?> id="first"><a href="index.php" class="Bold">Home</a></li>
<li <?php echo $active[1] ?>><a href="about.php" class="Bold">About</a></li>
<li <?php echo $active[2] ?>><a href="solutions.php" class="Bold">Solutions</a></li>
<li <?php echo $active[3] ?>><a href="services.php" class="Bold">Services</a></li>
<li <?php echo $active[4] ?>><a href="sustainability.php" class="Bold">Sustainability</a></li>
<li <?php echo $active[5] ?>><a href="healthcare.php" class="Bold">Healthcare</a></li>
<li <?php echo $active[6] ?>><a href="/blog/" class="Bold">Blog</a></li>
<li <?php echo $active[7] ?> id="last"><a href="contact.php" class="Bold">Contact</a></li>
</ul>
</nav>
Ok, so i thought I could do this like this, but perhaps not. Is this possible ?
$url = $_SERVER['REQUEST_URI'];
$active = 'class="bob"';
switch($url){
case('/index.php'):
$active[0] = ' class="active"';
break;
case('/about.php'):
case('/our-customers.php'):
case('/our-partners.php'):
case('/our-clients.php'):
case('/our-standards.php'):
case('/our-awards.php'):
$active[1] = ' class="active"';
break;
case('/solutions.php'):
$active[2] = ' class="active"';
break;
case('/services.php'):
$active[3] = ' class="active"';
break;
case('/sustainability.php'):
case('/what-are-we-doing.php'):
case('/what-can-you-do.php'):
case('/what-we-support.php'):
case('/references.php'):
$active[4] = ' class="active"';
break;
case('/healthcare.php'):
$active[5] = ' class="active"';
break;
case('/blog/'):
$active[6] = ' class="active"';
break;
case('/contact.php'):
$active[7] = ' class="active"';
break;
}
?>
?>
<nav>
<ul class="clearfix">
<li <?php echo $active[0] ?> id="first"><a href="index.php" class="Bold">Home</a></li>
<li <?php echo $active[1] ?>><a href="about.php" class="Bold">About</a></li>
<li <?php echo $active[2] ?>><a href="solutions.php" class="Bold">Solutions</a></li>
<li <?php echo $active[3] ?>><a href="services.php" class="Bold">Services</a></li>
<li <?php echo $active[4] ?>><a href="sustainability.php" class="Bold">Sustainability</a></li>
<li <?php echo $active[5] ?>><a href="healthcare.php" class="Bold">Healthcare</a></li>
<li <?php echo $active[6] ?>><a href="/blog/" class="Bold">Blog</a></li>
<li <?php echo $active[7] ?> id="last"><a href="contact.php" class="Bold">Contact</a></li>
</ul>
</nav>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将该行替换
为
Replace the line
by