我将here中的代码粘贴到了我的Web应用程序中。除了
Service C
下拉子菜单。我看不到Service C1
... Service C5
。
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> <span class="nav-label">Services</span> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service A</a></li>
<li><a href="#">Service B</a></li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="nav-label">Service C</span><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service C1</a></li>
<li><a href="#">Service C2</a></li>
<li><a href="#">Service C3</a></li>
<li><a href="#">Service C4</a></li>
<li><a href="#">Service C5</a></li>
</ul>
</li>
</ul>
</li>
</ul>
页面现在写:
The support for sub-menu was disabled in latest version of bootstrap. The option can be re-enabled by including a small CSS.
您知道所需的CSS及其放置位置吗?
我正在使用bootstrap 3.3.7,并且不想更改此版本。
答案 0 :(得分:1)
我做了一些更改看到它
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
</style>
</head>
<body>
<div class="container">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> <span class="nav-label">Services</span> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service A</a></li>
<li><a href="#">Service B</a></li>
<li class="dropdown-submenu">
<a class="test" href="#">Service C <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service C1</a></li>
<li><a href="#">Service C2</a></li>
<li><a href="#">Service C3</a></li>
<li><a href="#">Service C4</a></li>
<li><a href="#">Service C5</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
答案 1 :(得分:1)
.dropdown-menu
具有display:none
属性。您可以像这样轻松添加display:block
类:
$(document).ready(function(){
$('.dropdown-toggle').on("click", function(e){
$(this).next('.dropdown-menu').toggleClass("opened");
});
});
.opened {
display: block !important;
}
<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/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> <span class="nav-label">Services</span> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service A</a></li>
<li><a href="#">Service B</a></li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="nav-label">Service C</span><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Service C1</a></li>
<li><a href="#">Service C2</a></li>
<li><a href="#">Service C3</a></li>
<li><a href="#">Service C4</a></li>
<li><a href="#">Service C5</a></li>
</ul>
</li>
</ul>
</li>
</ul>