我想知道如何获取页面url以在我的侧导航栏中打开菜单



这是我的导航栏我想做的是编写javascript或jQuery来获取当前页面的url并打开相应的下拉容器我想打开侧导航的部分,这取决于我编写了这个javascript,但它不起作用

$(function() {
if (window.location.href.indexOf("home") > -1)
$('.dropdown-toggle.home').dropdown('toggle');
else if (window.location.href.indexOf("FRAMEWORKS") > -1)
$('.dropdown-toggle.FRAMEWORKS').dropdown('toggle');
else if (window.location.href.indexOf("Strategize phase") > -1)
$('.dropdown-toggle.Strategize phase').dropdown('toggle');
else if (window.location.href.indexOf("Standardize phase") > -1)
$('.dropdown-toggle.Standardize phase').dropdown('toggle');
else if (window.location.href.indexOf("Implement phase") > -1)
$('.dropdown-toggle.Implement phase').dropdown('toggle');
else if (window.location.href.indexOf("Integrate phase") > -1)
$('.dropdown-toggle.Integrate phase').dropdown('toggle');
else (window.location.href.indexOf("About") > -1)
$('.dropdown-toggle.ABOUT').dropdown('toggle');
});

主页

<button id class="dropdown-btn FRAMEWORKS" href="#">FRAMEWORKS    <i class="fa fa-caret-down"></i></button>

<div class="dropdown-container">
<div class="sub">
<a href="#">Framework</a>
<button class="dropdown-btn" href="#">Strategize phase<i class="fa fa-caret-down"></i></button>
<div class="dropdown-container">
<div class="subSub">
<a href="#">Enterprise Innovation Audit Canvas</a>
<a href="#">Pre-Audit Business Definition Questions</a>
<button class="dropdown-btn" href="#">Tools and Canvases for the Enterprise Innovation Capability Audit<i class="fa fa-caret-down"></i></button>
<div class="dropdown-container">
<div class="subSubSub">
<a href="#">Enterprise Innovation Maturity Canvas</a>
<a href="#">Enterprise Innovation Maturity Evaluation Grid Canvas</a>
<a href="#">Enterprise Innovation Maturity Road map Canvas</a>
</div>
</div>
</div>
</div>
</div>
<button class="dropdown-btn" href="#">Standardize Phaze<i class="fa fa-caret-down"></i></button>
<div class="dropdown-container">
<div class="subSub">
<button class="dropdown-btn" href="#">Innovation Culture Fostering Approach<i class="fa fa-caret-down"></i></button>
<div class="dropdown-container">
<div class="subSubSub">
<a href="#">Innovation Fostering Approach Summary</a>
<a href="#">4I- Inspire, Ideate, Implement and Impact Enterprise Innovation Fostering Model</a>
<a href="#">Enterprise Team Inventiveness Persona</a>
</div>
</div>

我真的不确定你的问题想要实现什么,但这里有一个基于bootstrap的与你的问题相关的小代码片段:

https://jsfiddle.net/vrjx2hde/4/

如果你想学习,试试这个链接。

如果你要在你的环境中使用它,你必须确保你的URL包含一个单词,你可以用找到它

window.location.href.indexOf(...)

例如:http://localhost/FRAMEWORKS.html

在这种情况下,您的"框架"下拉列表将在加载文档后打开。

$(document).ready(function(){
if (window.location.href.indexOf("FRAMEWORKS") > -1){
$('#my-id-FRAMEWORKS').dropdown("toggle");
}
});

最新更新