将活动类自动设置为菜单

时间:2016-02-14 07:52:22

标签: php html twitter-bootstrap

这里我创建了一个简单的菜单,使用php来包含该页面。我想把活动的课程设置为我站立的页面,但我不知道怎么办? 这是我的代码:

import Tkinter
   LevelBox = Tkinter.Tk()
   LevelBox.geometry("320x260")
   LevelBox.title("Diffuculty")
   LevelBox.withdraw()

   def Easy() :
    LevelBox.withdraw()
    easybox.deiconify()
    return

   def Moderate() :
    LevelBox.withdraw()
    moderatebox.deiconify()
    return

   def Hard() :
    LevelBox.withdraw()
    hardbox.deiconify()
    return

   b1 = Tkinter.Button (LevelBox, text="Easy",         command=Easy,height=1,width=7).grid(row=1,column=1,sticky="e",pady=5,padx=5)
   b1 = Tkinter.Button (LevelBox, text="Moderate", command=Moderate,height=1,width=7).grid(row=1,column=3,sticky="w",pady=5,padx=5)
   b1 = Tkinter.Button (LevelBox, text="Hard", command=Hard,height=1,width=7).grid(row=2,column=1,sticky="e",pady=5,padx=5)

   easybox = Tkinter.Toplevel()
   easybox.geometry("320x260")
   easybox.title("Easy Questions")
   easybox.withdraw()

   moderatebox = Tkinter.Toplevel()
   moderatebox.geometry("320x260")
   moderatebox.title("Moderate Questions")
   moderatebox.withdraw()

   hardbox = Tkinter.Toplevel()
   hardbox.geometry("320x260")
   hardbox.title("Hard Questions")
   hardbox.withdraw()

4 个答案:

答案 0 :(得分:2)

示例:

<li><a href="index.php?page=collections">Collections<span> </span></a></li>

成为

<li<?= $_GET['page'] == 'collections' ? ' class="active"' : ''; ?>><a href="index.php?page=collections">Collections<span> </span></a></li>

答案 1 :(得分:1)

在调用包含导航栏的头文件之前设置活动页面变量。请注意,每个页面都需要一个唯一的名称才能称为activePage。

<?php
    $activePage="home"; 
    $header = "includes/pageHeader.php";
    include($header);   
?>

然后在每个li的导航菜单中插入php检查如下 - 如果activePage与检查相同 - 它会将活动类添加到li。

<li class="navLink <?php if($activePage == "home"){echo"active";}?>"><a href="index.php">HOME</a></li>
<li class="navLink <?php if($activePage == "aboutus"){echo"active";}?>"><a href="aboutus.php">About Us</a></li>
etc....

等等通过导航菜单中的其余链接

答案 2 :(得分:0)

此外,您可以使用php_selfQUERY_STRING

PHP:

  <? if(strpos($_SERVER['QUERY_STRING'], 'collections' ) !== false

答案 3 :(得分:0)

如果您需要更多详细信息,请参阅

<div class="top-nav">
<div class="container">
    <span class="menu"> </span>
    <ul>
        <li class="<? if(strpos($_SERVER['QUERY_STRING'], 'home' ) !== false) echo 'active';?>"><a href="index.php?page=home">Home<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], 'collections' ) !== false) echo 'active';?>" href="index.php?page=collections">Collections<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], '404' ) !== false) echo 'active';?>" href="index.php?page=404">New Arrivals<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], '404' ) !== false) echo 'active';?>" href="index.php?page=404">Sale<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], '404' ) !== false) echo 'active';?>" href="index.php?page=404">Accessories<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], 'about' ) !== false) echo 'active';?>" href="index.php?page=about">About Us<span> </span></a></li>
        <li><a class="<? if(strpos($_SERVER['QUERY_STRING'], 'contact' ) !== false) echo 'active';?>" href="index.php?page=contact">Contact Us<span> </span></a></li>
        <div class="clearfix"> </div>
    </ul>
    </div>
    </div>

但是您有更多相同page-404

的网页