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 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c