[英]i want to know how to get page url to open a menu in my sidenav bar
this is my navbar what i want to do is write javascript or jQuery to get the current pages url and open the corresponding dropdown container i want to open the part of the side nav depending on the url i have this javascript written but it doesnt work
$(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");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.