显示具有不同菜单项的同一页面

时间:2017-07-04 15:28:46

标签: javascript php html css html5

我的帮助手册中有这两个菜单和子菜单,其中有一个页面leftmenu.php,其中包含所有菜单,并且我已将此文件包含在我的所有页面上。

<li>
    <a href=""><i class="fa fa-briefcase"></i> <span class="nav-label">Main menu 1 </span><span class="fa arrow"></span></a>
    <ul class="nav nav-second-level collapse">
        <li><a href="project.php">Project Management</a></li>
        <li><a href="task.php">Task Management</a></li>
        <li><a href="defect.php">Defect Management</a></li>
        <li><a href="customer1.php">Customer Management</a></li>
        <li><a href="user.php">User Management</a></li>
        <li><a href="settings.php">Settings</a></li>
    </ul>
</li>
<li>
    <a href=""><i class="fa fa-ticket"></i> <span class="nav-label">Main menu 2 </span><span class="fa arrow"></span></a>
    <ul class="nav nav-second-level collapse">
        <li><a href="ticket.php">Ticket Management</a></li>
        <li><a href="resolution.php">Resolutions</a></li>
        <li><a href="customer.php">Customer Management</a></li>
        <li><a href="user.php">User Management</a></li>
        <li><a href="settings.php">Settings</a></li>
    </ul>
</li>

现在我有一个customer.php,我想在菜单中使用,但点击客户管理的菜单应该只有活动状态。 如何实现这一点,因为我只使用php和html。 三江源

我的代码现在:

<li <?= active('leads|user|settings')?>>
                    <a href=""><i class="fa fa-diamond"></i> <span class="nav-label">Main menu1</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li <?= active('leads') ?>><a href="leads.php">Lead Management</a></li>
                        <li <?= active('user') ?>><a href="user.php">User Management</a></li>
                        <li <?= active('settings') ?>><a href="settings.php">Settings</a></li>
                    </ul>
                </li>

                <li <?= active('project|task|defect|customer1|users|settings1')?>>
                    <a href=""><i class="fa fa-briefcase"></i> <span class="nav-label">Main menu2 </span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                      <li <?= active('project') ?>><a href="project.php">Project Management</a></li>
                        <li <?= active('task') ?>><a href="task.php">Task Management</a></li>
                        <li <?= active('defect') ?>><a href="defect.php">Defect Management</a></li>
                        <li <?= active('customer1') ?>><a href="customer1.php">Customer Management</a></li>
                        <li <?= active('users') ?>><a href="users.php">User Management</a></li>
                        <li <?= active('settings1') ?>><a href="settings1.php">Settings</a></li>
                    </ul>
                </li>

2 个答案:

答案 0 :(得分:1)

function active($page) {
    if (preg_match("/$page\./",$_SERVER["PHP_SELF"])) {
        echo "class=active";
    }
}

实施例

<li><a href=index.php <?= active('index') ?>>Home</a></li>

修改
和主菜单1的示例

<a <?= active('project|task|defect|customer1|user|settings') ?> href=""><i class="fa fa-briefcase"></i> <span class="nav-label">Main menu 1 </span><span class="fa arrow"></span></a>

答案 1 :(得分:0)

我会在你想要显示的每个值中将它包装在这样的php if语句中

if ($_SERVER['REQUEST_URI'] == "my/url/") {
// do something
} else {
// do something else
}