Twitter Bootstrap:如何获取下拉列表的选定值? [英] Twitter Bootstrap: How do I get the selected value of dropdown?
问题描述
我需要获取用户从twitter启动下拉列表中选择的值。一旦用户选择一个值,我想要下拉列表显示该值。所以,用户选择挂起,然后我想更改从中选择的下拉值,当用户完成表单,我想检索所选的值。是否有人可以指出正确的方向?
I need to get the value a user selects from a twitter bootstrap dropdown. Once the user selects a value I want the dropdown to display that value. So, the user selects 'pending' then I want to change the selected dropdown value from that and, when the user completes the form, I want to retrieve the selected value. Would someone be able to point me in the right direction?
<div class="btn-group">
<i class="dropdown-arrow dropdown-arrow-inverse"></i>
<button class="btn btn-primary">status</button>
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-inverse">
<li><a href="#fakelink">pending</a></li>
<li><a href="#fakelink">active</a></li>
<li><a href="#fakelink">discontinued</a></li>
</ul>
</div>
感谢,
Matt
Thanks, Matt
推荐答案
Bootstrap为您的实现提供了最低要求的功能,他们不是下拉,而是他们只是ul,li的css应用它和一些事件注册在引导插件中切换按钮将其显示为下拉菜单。
Bootstrap provides you with minimum required functionality for your implementation, they aren't dropdowns instead they are mere ul, li's with css applied on it and some events registered in the bootstrap plugin for toggling the button to display them as dropdown. This one you need to do on your own.
设置状态按钮的一些标识符,说一个className btnStatus
并将点击事件绑定到下拉链接。并做这样的事情?
Set up some identifier to the status button say a className btnStatus
and bind a click event to the dropdown links. and do something like this?
$('.dropdown-inverse li > a').click(function(e){
$('.btnStatus').text(this.innerHTML);
});
Demo
这篇关于Twitter Bootstrap:如何获取下拉列表的选定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!