【问题标题】:Bootstrap-3-typeahead: How to change focus to another input after selected item into dropdownlist?Bootstrap-3-typeahead:如何在选定项目进入下拉列表后将焦点更改为另一个输入?
【发布时间】:2020-02-06 03:09:42
【问题描述】:

我正在使用Bootstrap 3 Typeahead 4.0.2,我想知道在我选择列表中的一个项目后如何将 Typeahead 输入焦点更改为另一个输入文本?我发现了一些类似的问题,但我没有找到解决这个问题的正确方法:

  1. Angularjs ui typeahead to focus after select
  2. Focus on other input after typeahead-on-select angular-ui-bootstrap
  3. How to get Bootstrap typeahead click result before the input change event

当我在输入文本中选择某个项目时,焦点保持在此输入文本上,但我想在选择一个项目后将此焦点更改为下一个输入文本。下面是我正在使用的 html 代码和 bootstap typeahead:

HTML

<input type="text" name="products" id="products" data-provide="typeahead" class="form-control typeahead" autocomplete="off" placeholder="Type something" />

<input type="text" name="price" id="price" placeholder="Type price" />

Bootstrap 3 Typeahead

            $('#products').typeahead({ 

                source: function ( query, result )  

                {
                    result ( $.map(data, function (item)
                        {
                            return item.product;
                        }
                    ));

                },

                  afterSelect: function(data) {

   $('#price').focus();

  },    

    });

作为上面的 Typeahead 代码,我尝试在 Typeahead afterSelect 事件中插入 jquery 焦点事件 $('#price').focus(); 但不起作用。在这种情况下,我该如何解决?

【问题讨论】:

    标签: jquery typeahead.js bootstrap-typeahead


    【解决方案1】:

    我在link 中找到了答案。我只是在 Typeahead afterSelect 事件中插入下面的代码:

    setTimeout("$('#price').focus();", 0)
    

    上面的代码运行良好,但我不知道为什么 setTimeout 具有在我选择列表中的项目时更改焦点的功能。无论如何,它对我有用:p

    【讨论】:

      猜你喜欢
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多