【发布时间】:2016-11-19 21:58:02
【问题描述】:
我有一个在单击文本框时显示的有效下拉列表,但希望它始终显示在 keyup 上。我有 keyup 功能,但您仍然需要在键入后单击以显示下拉菜单。
//This calls the delay function and will result in the customerNameUL_Populate function being called after the delay has passed.
function customerNameSearchTextbox_keyup() {
delay(function () {
if ($('#customerNameSearchTextbox').val().length > 0) {
customerNameUL_Populate();
alert('dropdown'); //http://getbootstrap.com/javascript/#dropdowns
$('#customerNameSearchTextbox').dropdown(); <----- ?
}
else {
$('#customerNameUL').empty();
};
}, 500);
};
//This function gets called to populate the list of customers for search
function customerNameUL_Populate() {
<working stuff>
};
<div class="dropdown">
<input type="text" id="customerNameSearchTextbox" class="form-control" placeholder="Customer" aria-describedby="basic-addon1" data-toggle="dropdown" onkeyup="customerNameSearchTextbox_keyup();" autocomplete="off">
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" id="customerNameUL">
</ul>
</div>
我认为我的困惑是要调用什么事件,或者要分配什么类,或者要调用什么事件。上面的警报显示我到达了我想去的地方,只需要替换下面的行以显示 customerNameUL。
【问题讨论】:
-
我相信——这主要是一个简单的例子——你的问题主要是由于通过点击调用切换下拉的代码查找他们使用的数据切换属性。如果您要说,将数据切换添加到另一个未显示的元素,只需调用
$().dropdown(),您就可以做您想做的事情
标签: jquery twitter-bootstrap dropdown