简体   繁体   English

包含活动菜单中的javascript菜单

[英]Include javascript menu with active class

I want to include this menu to my web page with following index page code: 我想使用以下索引页面代码将此菜单包含在我的网页中:

<div id="header"><?php include "shared/header.php"; ?></div>        
<div id="container">
    <div id="menu"><?php include "shared/menu.php"; ?></div>
    <div id="content"></div>
</div>
<div id="footer"><?php include "shared/footer.php"; ?></div>

And my submenu items have links like: index.php?page=page_something&id=1 . 我的子菜单项具有如下链接: index.php?page=page_something&id=1

As you can see in the jsfiddle code, active menu style is different than the inactive ones. 正如您在jsfiddle代码中看到的那样,活动菜单样式与非活动菜单样式不同。 So there is no problem. 因此没有问题。 But when I using this code in my web page, this does not work. 但是,当我在网页中使用此代码时,这将无法正常工作。

When I click a menu and load a new page, active menu style is gone and it turns to initial style. 当我单击菜单并加载新页面时,活动菜单样式消失了,而变为初始样式。 So users can't figure out which page they are visiting right now. 因此,用户无法确定他们现在正在访问哪个页面。 I hope I could explain my problem. 我希望我能解释我的问题。

Forgive me as I'm not familiar with PHP, but if you are loading a completely new page each time, then the accordion is going to reset to whatever the JS is that you have on that page. 原谅我,因为我不熟悉PHP,但是如果您每次都加载一个全新的页面 ,那么手风琴将重置为该页面上的JS。

Unless you are altering only part of the page, hard-coding default accordion settings on each page, or somehow storing session variables on the browser and consuming them via JS, then there's no way for the accordion to keep its state as you navigate across pages. 除非您仅更改页面的一部分,在每个页面上硬编码默认的手风琴设置,或者以某种方式在浏览器中存储会话变量并通过JS使用它们,否则手风琴无法在浏览页面时保持其状态。

EDIT: I see you are passing some parameters in your query string. 编辑:我看到您正在您的查询字符串中传递一些参数。 But I don't see in your JS where you are parsing them in your page/accordion initialization. 但是我看不到您的JS在页面/手风琴初始化中解析它们的位置。

try someting like this : 尝试这样的东西:

<div id="header"><?php include "shared/header.php"; ?></div>        
<div id="container">
    <div id="menu"><?php include "shared/menu.php"; ?></div>
    <div id="content">
    <?php
    if(isset($_GET['page'])){
        include 'shared/'.$_GET['page'].'.php';
    }
    ?>
    </div>
</div>
<div id="footer"><?php include "shared/footer.php"; ?></div>

I hope this help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM