dqjl0906 2014-06-15 19:21
浏览 30
已采纳

外部导航栏 - 如何查找当前页面

I want a navigation bar on the top of my site. I use a external file for this navbar.

<div data-role="navbar">
    <ul>
        <li><a href="#home">Startseite</a></li>
        <li><a href="#library">Bibliothek</a></li>
        <li><a href="#statistics">Statistik</a></li>
    </ul>
</div>

But now I want to set the class ui-btn-active and ui-state-persist so I know on wich page I am currently. So my question is how I do I find out on wich page I am currently so I am able to set this class. I also post here one of the pages.

<div data-role="page" id="statistics">
    <div data-role="header">
        <h1>Statistik</h1>
        <?php
            include './static/navbar.php';
        ?>
    </div>

    <div data-role="main" class="ui-content">
    </div>
</div>

I am using a lamp server so I have the ability to use php.

  • 写回答

1条回答 默认 最新

  • doumiyi7063 2014-06-16 07:02
    关注

    The # param in url is a browser parameter, so php can't obtain this (I think). You must use javascript to check total url with document.URL and post it to a php via ajax. When php recibe the data you can use this to obtain THE NEXT OF#, the anchor that you want.

    $foo = parse_url('http://www.example.com/index.php#action', PHP_URL_FRAGMENT);
    

    Car read about this here http://php.net/manual/en/function.parse-url.php

    But I think that you can select the buttons only with javascript. Taking the url you can process it and take only after # and add a class to the button that match. Here are good ino to take anchor How to get the anchor from the URL using jQuery?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 找人不需要人工智能回答的gamit解算后做形变分析
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错