gpt4 book ai didi

javascript - 在 Bootstrap (AdminLTE) 上的下拉菜单上显示事件菜单

转载 作者:行者123 更新时间:2023-12-01 00:34:24 31 4
gpt4 key购买 nike

我想突出显示侧栏菜单上的事件页面。我正在使用 Bootstrap (AdminLTE)。

我尝试了很多javascript方法都没有效果。请任何人帮忙。下面是侧边栏菜单。

<ul class="sidebar-menu" >
<li class=""><a href="/dashboard"><i class="fa fa-dashboard"></i> <span>Dashboard</span></a> </li>
<br>
<li class="treeview">
<a href=""> <i class="fa fa-cogs"></i> <span> Account Configuarion</span> <i class="fa fa-angle-left pull-right"></i> </a>
<ul class="treeview-menu">
<li class="treeview">
<a href=""> <i class="fa fa-mobile fa-lg"></i> <span>M-PESA C2B</span> <i class="fa fa-angle-left pull-right"></i> </a>
<ul class="treeview-menu">
<li class=""><a href="/c2b"><i class="fa fa-arrow-circle-right"></i>C2B Settings</a></li>
<li class=""><a href="/online-checkout"><i class="fa fa-arrow-circle-right"></i> Online CheckOut</a></li>
<li class=""><a href="/stk-push"><i class="fa fa-arrow-circle-right"></i> STK Push</a></li>
</ul>
</li>
<li class="treeview">
<a href=""> <i class="fa fa-mobile fa-lg"></i> <span>M-PESA B2C</span> <i class="fa fa-angle-left pull-right"></i> </a>
<ul class="treeview-menu">
<li><a href="b2c-documentation"><i class="fa fa-arrow-circle-right"></i> B2C Settings</a></li>
</ul>
</li>
<li class="treeview">
<a href=""> <i class="fa fa-send"></i> <span>SMS</span> <i class="fa fa-angle-left pull-right"></i> </a>
<ul class="treeview-menu">
<li class=""><a href="/sms-setting"><i class="fa fa-arrow-circle-right"></i>SMS Settings</a></li>
<li class=""><a href="/subscription"><i class="fa fa-arrow-circle-right"></i>Subscription SMS Settings</a></li>
</ul>
</li>
</ul>
</li>

<li class="treeview ">
<a href="#"> <i class="fa fa-cogs"></i> <span>Account Info</span> <i class="fa fa-angle-left pull-right"></i> </a>
<ul class="treeview-menu">
<li class=""><a href="buy-units"><i class="fa fa-arrow-circle-right"></i> Buy Units</a></li>
<li class=""><a href="/account-details"><i class="fa fa-arrow-circle-right"></i>Account Details</a></li>
<li class=""><a href="/users"><i class="fa fa-arrow-circle-right"></i>Account Users</a></li>
</ul>
</li>
</ul>

我尝试使用此 JavaScript 代码,但最终打开了所有下拉菜单。尽管如此,它确实突出显示了当前项目。但我希望其他项目保持关闭状态,只有事件项目保持打开状态。

<script>
$(document).ready(function() {
var url = window.location;
var element = $('ul.sidebar-menu a').filter(function() {
return this.href == url || url.href.indexOf(this.href) == 0; }).parent().addClass('active');
if (element.is('li')) {
element.addClass('active').parent().parent('li').addClass('active')
}
});
</script>

最佳答案

/** 试试这个 ** > 对于 adminLTE 中的侧边栏和 TreeView 菜单,它将在单击时添加事件并删除任何以前的事件类/** 添加事件类并删除先前单击的菜单 */

var url = window.location;
// for sidebar menu but not for treeview submenu
$('ul.sidebar-menu a').filter(function() {
return this.href == url;
}).parent().siblings().removeClass('active').end().addClass('active');
// for treeview which is like a submenu
$('ul.treeview-menu a').filter(function() {
return this.href == url;
}).parentsUntil(".sidebar-menu > .treeview-menu").siblings().removeClass('active menu-open').end().addClass('active menu-open');

关于javascript - 在 Bootstrap (AdminLTE) 上的下拉菜单上显示事件菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45204906/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com