简体   繁体   English

引导导航栏类=来自单独页面时的活动更改

[英]bootstrap navbar class=active change when coming from a separate page

I've been trying out solutions to similar cases but none of them work so far. 我一直在尝试解决类似情况的解决方案,但到目前为止,它们都没有起作用。

Here's the problem, I have 2 html files total. 这是问题,我总共有2个html文件。 On my navigation bar, I have 4 options. 在我的导航栏中,我有4个选项。 3 of them refer to id's on the same page(index) and the 4th refers to the separate page. 其中3个是指同一页面(索引)上的ID,第4个是指单独的页面。 Now coming from the separate page back to the index, the active menu item isn't the right "active" one. 现在从单独的页面返回索引,活动菜单项不是正确的“活动”项。 Like if I click on 'about' on the support page, the active menu item is 'home'. 就像我在支持页面上单击“关于”一样,活动菜单项是“主页”。 or if I click on 'contact', the active menu item becomes 'about'. 或者,如果我单击“联系人”,则活动菜单项将变为“关于”。 The content that appears is correct. 出现的内容正确。 But the active menu item isn't. 但是活动菜单项不是。

Here's from the index.html file: 这是来自index.html文件的信息:

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav navbar-right">
        <li class="current"><a href="#home">Home</a></li>
        <li><a href="#about">About</a></li>
        <li class="support" ><a href="support.html">Support</a></li>
        <li ><a href="#contact">Contact</a></li>
</ul>
</div>

and here's from support.html : 这是来自support.html

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav navbar-right">
        <li><a href="index.html#home">Home</a></li>
        <li><a href="index.html#about">About</a></li>
        <li class="current"><a href="#support">Support</a></li>
        <li ><a href="index.html#contact">Contact</a></li>
    </ul>
</div>

This is one of the solutions that I tried with no results: https://stackoverflow.com/a/11539359 这是我尝试的没有结果的解决方案之一: https : //stackoverflow.com/a/11539359

JS is not my strong suit, thank you so much for your help! JS不是我的强项,非常感谢您的帮助!

There were lot of issues with the way you are loading scripts for example 例如,加载脚本的方式存在很多问题

 $(document).ready(function() {
        $('#ind').cycle({
            fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        });
    });

you are calling this before the jquery is loaded so it gives $ is undefined error , so the solution is to move all the script at the end, and there is one inline script also for menu handler, move that to document ready functions 您是在加载jquery之前调用此函数的,因此它给出$是未定义的错误 ,因此解决方案是将所有脚本移到末尾,并且还有一个用于菜单处理程序的内联脚本,将其移至文档就绪函数

I have included the fix in the following file HTML Zip files , you will find all JS moved to end. 我已在以下文件HTML Zip文件中包含此修复程序,您会发现所有JS都已移至末尾。 Its working fine for me now 现在对我来说很好

One more thing make your contact height same as other container or remove extra margin/padding from Physicians section 还有一件事情使您的接触高度与其他容器相同,或者从“内科医生”部分删除了多余的空白/填充

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

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