【发布时间】:2014-10-09 14:33:35
【问题描述】:
我有一个无序列表(下面是 HTML,下面是 Javascript 代码)。
第一个函数“display_dropdown_multiple”对我有用。但是,我遇到了问题 第二个函数“get_selected_owner”。
从下拉菜单中进行选择后。我希望第二个函数返回“选定值”。任何帮助将不胜感激。
function display_dropdown_multiple(event) {
$(".dropdown-menu").on('click', 'li a', function(){
$(this).parents(".btn-group").find('.btn').text($(this).text());
$(this).parents(".btn-group").find('.btn').val($(this).data('value'));
});
});
function get_selected_owner() {
return $('#owner').find('option:selected').val();
});
});
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle" id="owner" data-toggle="dropdown">
Owner <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="owner-dropdown-menu">
<li role="presentation" class="dropdown-header">major</li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" id="owner"><input type="hidden" onclick='display_dropdown_multiple(event)' id="ownerId" name="ownerId" value="Owner 1" >Owner 1</a></li>
<li class="divider"></li>
<li role="presentation" class="dropdown-header">minor</li>
<li><a href="#" id="owner"><input type="hidden" onclick='display_dropdown_multiple(event)' id="ownerId" name="ownerId" value="Owner 2" >Owner 2</a></li>
<li><a href="#" id="owner"><input type="hidden" onclick='display_dropdown_multiple(event)' id="ownerId" name="ownerId" value="Owner 3" >Owner 3</a></li>
</ul>
</div>
【问题讨论】:
标签: javascript jquery html twitter-bootstrap