如何使用Bootstrap typeaheads插件Typeahead.js停止悬停以设置typeahead输入的值?

时间:2018-04-04 08:19:32

标签: jquery twitter-bootstrap bootstrap-4 typeahead.js typeahead

我有一个使用bootstrap typeahead plugin的简单ASP.NET MVC应用程序。

我有一个类型如下的预先输入:

enter image description here

此处直到我点击才会选中项目。但是,假设我没有点击就将鼠标悬停在列表中:

enter image description here

但是当我将鼠标移到窗体外时,悬停的项目现在变为选中状态:

enter image description here

这意味着如果我点击网站上的任何地方,那么预先输入的val()就会成为之前悬停的项目。

如果单击类型清单中的项目,如何确保仅设置val()

我已经设置了autoSelect: false设置,如果我还没有徘徊(默认选择第一项),这就解决了问题。

1 个答案:

答案 0 :(得分:2)

我的解决方案是编辑插件。一点都不难

  1. 从存储库bootstrap3-typeahead.js
  2. 下载插件
  3. 转到第575行并对该行进行评论。
  4. blur: function (e) {
          if (!this.mousedover && !this.mouseddown && this.shown) {
            //this.select();
            this.hide();
            this.focused = false;
            this.keyPressed = false;
          } else if (this.mouseddown) {
            // This is for IE that blurs the input when user clicks on scroll.
            // We set the focus back on the input and prevent the lookup to occur again
            this.skipShowHintOnFocus = true;
            this.$element.focus();
            this.mouseddown = false;
          } 
    },
    
    1. 替换代码:)
    2. 这应该有效!适合我;)