我已经尝试过Multi-Level Drop Down了。当我有2个或更多下拉子菜单。当我点击第一个下拉列表然后我点击另一个下拉列表时,第一个下拉列表仍然打开。我希望当我点击第二个下拉列表时,第一个下拉列表将关闭,或者当我点击下拉列表时,所有子下拉列表将关闭。
if (cluster.isMaster) {
cron.schedule('*/1 * * * *', function() {
//CRON JOB
})
// continue initializing workers here
}
答案 0 :(得分:2)
你可以使用CSS,jQuery addClass('active')
&在CSS中toggleClass('active')
,你必须为所有dropmenu {/ 1>} display: none;
你去吧
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
$(function () {
$('#drop1').on('click', function(){
$('.dropmenu1').toggleClass('active');
$('.dropmenu2').removeClass('active');
});
$('#drop2').on('click', function(){
$('.dropmenu1').removeClass('active');
$('.dropmenu2').toggleClass('active');
});
$('#drop3').on('click', function(){
$('.dropmenu3').toggleClass('active');
});
$('#drop4').on('click', function(){
$('.dropmenu4').toggleClass('active');
});
$('#button-t').on('click', function(){
$('.dropmenu1').removeClass('active');
$('.dropmenu2').removeClass('active');
$('.dropmenu3').removeClass('active');
$('.dropmenu4').removeClass('active');
});
});
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
ul.dropdown-menu ul.dropdown-menu{
display:none !important;
}
ul.dropdown-menu ul.dropdown-menu.active{
display:block !important;
}
ul.dropdown-menu ul
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<h2>Multi-Level Dropdowns</h2>
<p>In this example, we have created a .dropdown-submenu class for multi-level dropdowns (see style section above).</p>
<p>Note that we have added jQuery to open the multi-level dropdown on click (see script section below).</p>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="button-t">Tutorials
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">HTML</a></li>
<li><a tabindex="-1" href="#">CSS</a></li>
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#" id="drop1"> New dropdown 1 <span class="caret"></span></a>
<ul class="dropdown-menu dropmenu1">
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li class="dropdown-submenu">
<a class="test" href="#" id="drop3">Another dropdown <span class="caret"></span></a>
<ul class="dropdown-menu dropmenu3">
<li><a href="#">3rd level dropdown</a></li>
<li><a href="#">3rd level dropdown</a></li>
</ul>
</li>
</ul>
</li>
<li class="dropdown-submenu" >
<a class="test" tabindex="-1" href="#" id="drop2">New dropdown 2 <span class="caret"></span></a>
<ul class="dropdown-menu dropmenu2">
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li><a tabindex="-1" href="#">2nd level dropdown</a></li>
<li class="dropdown-submenu">
<a class="test" href="#" id="drop4">Another dropdown <span class="caret"></span></a>
<ul class="dropdown-menu dropmenu4">
<li><a href="#">3rd level dropdown</a></li>
<li><a href="#">3rd level dropdown</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>