我必须让ul像下拉列表一样。我尝试使用以下代码。如果我从ul中选择一个值,它会在selected_category
中写入,但如果我想从ul更改所选值,我就不能这样做。哪里错了?
$(function() {
$( document.body ).on( 'click', '.category_dropdown li', function( event ) {
var $target = $( event.currentTarget );
$target.closest( '.btn-group' )
.find( '#selected_category' ).text( $target.text() )
.end()
.children( '.category_dropdown' ).dropdown( 'toggle' );
return false;
});
});

<div class="btn-group">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span id="selected_category"></span>
<span class="caret" id="caret_black"></span>
</a>
<ul class="dropdown-menu category_dropdown">
<li class="category_select" >
<a href="#">
Choose
</a>
</li>
<li>
<a href="#"
Value 1
</a>
</li>
<li>
<a href="#">
Value 2
</a>
</li>
</ul>
</div>
&#13;