gpt4 book ai didi

jquery - 可点击的多级菜单

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:34 25 4
gpt4 key购买 nike

我想做一个像这样的菜单http://bootsnipp.com/snippets/featured/multi-level-dropdown-menu-bs3 ,它必须是多级菜单,但我只想通过点击打开菜单,还有多级元素,而不是鼠标悬停。此外,如果菜单打开并单击正文将关闭所有菜单。有人知道吗?

提前致谢。

HTML

<div class="container">
<div class="row">
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li><a href="#">Some action</a></li>
<li><a href="#">Some other action</a></li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Hover me for more options</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level</a></li>
<li class="dropdown-submenu">
<a href="#">Even More..</a>
<ul class="dropdown-menu">
<li><a href="#">3rd level</a></li>
<li><a href="#">3rd level</a></li>
</ul>
</li>
<li><a href="#">Second level</a></li>
<li><a href="#">Second level</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>

CSS

.dropdown-submenu {
position: relative;
}

.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}


.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}

.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}

.dropdown-submenu.pull-left {
float: none;
}

.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}

JS

$(function(){
$(".dropdown-submenu").on("click",function(e){
var current=$(this).find(".dropdown-menu");
current.toggle();
e.stopPropagation();
});
});

最佳答案

解决方法是:

JS

$(function(){
$(".dropdown-submenu").on("click",function(e){
var current=$(this).find(".dropdown-menu").first();
console.log(current);
current.toggle();
e.stopPropagation();
});


$(document).click(function(){
$(".dropdown-menu").hide('slow');
});


});

关于jquery - 可点击的多级菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38589931/

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