doupian6118 2014-09-25 13:33
浏览 60
已采纳

将CSS类应用于从同一页面,不同部分的多个链接中单击的链接

I have 3 links that all point to the same page but to different sections.

This is what the page sections look like, they are all similar- just read from different tables.

<h1>Networking</h1>
<?php 
  include 'inc/connect.php';
  $data = mysqli_query($link, "SELECT * FROM networking WHERE id = 1")or 
                       die(mysqli_error($link));           
  while($info = mysqli_fetch_array( $data )) {
    echo nl2br($info['info']);}
?>  
</article>

This is the part of the menu file that has a link to 'Networking'.

if ($page == 'system') { 
 $output .="<li><a href='system.php#networking' class='active'>Networking</a></li>";}
 else{
   $output .="<li><a href='system.php#networking'>Networking</a> </li>";}

All the page section are in a page called system.php. In the head of system.php I have this line

<?php $page = 'system'; ?>

This so I can apply the css class 'active' to the active link.

The way it is now, when I click on any 1 of my same page different section link the the class 'active' is applied to all 3 menu items.

Is there a way that I can apply the class to only the clicked link?

  • 写回答

2条回答 默认 最新

  • doxd96148 2014-09-25 13:41
    关注

    I understand your problem, you could do something like this:

    system.php?section=networking#networking
    

    And do this at the top:

    <?php $page = 'system'; $section=$_GET['section']; ?>
    

    And then change your if statement to:

    if ($page == 'system' AND $section == 'networking') { 
    

    Note: this is not the best solution, but uses your style, I hope this will help you!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作