jquery - bootstrap-typeahead.js 在 select 事件上添加监听器

标签 jquery jquery-ui twitter-bootstrap

我是 Bootstrap Twitter 框架的新手,我需要使用 bootstrap-typeahead.js 进行自动完成,但我还需要获取用户为 typeahead 选择的值。

这是我的代码:

<input type="text" class="span3" style="margin: 0 auto;" 
                   data-provide="typeahead" data- items="4" 
                   data-source='["Alabama","Alaska"]'>

如何添加监听器以从 typeahead 类型中获取所选值并将其传递到函数中?例如,当我使用 ExtJs 时,我应用以下结构:

listeners: {
   select: function(value){
     ........
   }
}

我怎样才能通过预先输入来做类似的事情?

最佳答案

您应该使用“更新程序”:

$('#search-box').typeahead({

    source: ["foo", "bar"],

    updater:function (item) {

        //item = selected item
        //do your stuff.

        //dont forget to return the item to reflect them into input
        return item;
    }
});

关于jquery - bootstrap-typeahead.js 在 select 事件上添加监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9496314/

相关文章:

jquery - 如何在jquery中计算 "visible"选项卡?

IE9+ 中带填充的 jQuery UI .addClass() 动画

html - 获取 Bootstrap div 中的文本以环绕并在与其水平相邻的列下方

jquery - 在 IE8 中,jquery-ui 的对话框将其内容的高度设置为零。我怎样才能解决这个问题?

jquery - Twitter BootStrap 模态窗口后备链接

javascript - 使用 AJAX 的数据表中的子行

jquery - 如何在 AJAX 调用期间获取等待加载程序

javascript - 绑定(bind)已经绑定(bind)到另一个元素的函数

html - Bootstrap 导航栏折叠样式不正确

javascript - Bootstrap 按钮水平居中