以下是我尝试实施的一个示例:
如何在点击下拉菜单中创建文本表单。按照示例,如何将登录(当前在导航栏中)移动到下拉菜单并仍然保留点击时的操作(但现在显示下拉菜单中的文本框和登录按钮)?
答案 0 :(得分:1)
您最终可以像添加任何其他元素一样添加表单。
.navbar .dropdown-menu {
width: 300px;
padding: 10px;
}
.navbar .dropdown-menu {
border-radius: 0;
box-shadow: none;
}
.navbar .dropdown-menu form .form-group .form-control,
.navbar .dropdown-menu form .form-group label,
.navbar .dropdown-menu form .form-group .btn-primary {
margin: 5px 0;
}

<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a>
</li>
<li><a href="#">Link</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>
<form action="#">
<div class="form-group">
<label for="username">Username</label>
<input class="form-control" type="text" name="username" />
<label for="password">Password</label>
<input class="form-control" type="password" name="password" />
<input class="btn btn-default" type="submit" name="submit" value="Sign In" />
</div>
</form>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
&#13;