gpt4 book ai didi

javascript - 下拉菜单 ... 带有 Bootstrap 的下拉菜单

转载 作者:行者123 更新时间:2023-11-30 12:35:06 26 4
gpt4 key购买 nike

我需要在 Bootstrap 3 的下拉菜单中放置一个下拉菜单 ... .

enter image description here

不幸的是,当我点击第二个下拉菜单时,它没有显示。

如何在单击时显示第二个下拉菜单?那么我如何(使用 JS 或 jQuery)处理第二个下拉菜单的状态变化?


HTML:

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div>
<ul class="nav navbar-nav">
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Settings<span class="caret"></span></a>

<ul class="dropdown-menu" role="menu">
<li><a href="#">Edit</a>
</li>
<li><a href="#">Delete</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Visible by friends<span class="caret"></span></a>

<ul class="dropdown-menu" role="menu">
<li><a href="#">Visible by friends</a>
</li>
<li><a href="#">Visible by me only</a>
</li>
<li><a href="#">Visible by anyone</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>

最佳答案

添加以下javascript:

$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
// Avoid following the href location when clicking
event.preventDefault();
// Avoid having the menu to close when clicking
event.stopPropagation();
// If a menu is already open we close it
$('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open');
// opening the one you clicked on
$(this).parent().addClass('open');
});

Demo可以看here .

关于javascript - 下拉菜单 ... 带有 Bootstrap 的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26308557/

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