使用Bootstrap 3.x,以下内容生成一个下拉菜单。我需要一个下拉菜单,其行为类似于HTML表单,下拉菜单中的每个项目都有(预定)值。我如何结合这两件事来获得具有Bootstrap btn-group风格的HTML表单的功能?
<!-- Single button -->
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Action <span class="caret"></span>
</button>
<form>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
答案 0 :(得分:5)
你可以这样做..
<!-- Single button -->
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<form>
<div class="form-group">
<input type="email" class="form-control" id="inputEmail1" placeholder="Email">
</div>
<div class="form-group">
<input type="password" class="form-control" id="inputPassword1" placeholder="Password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</form>
</ul>
并使用jquery来防止下拉菜单关闭...
$('.dropdown-menu>form').click(function(e){
e.stopPropagation();
});