【问题标题】:Bootstrap typeahead doesnt workBootstrap 预输入不起作用
【发布时间】:2014-08-19 13:38:45
【问题描述】:

有人可以帮助找出这段代码有什么问题吗,预先输入似乎不起作用。任何帮助都非常受欢迎。

<html>
  <head>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div style="margin: 50px 50px">
      <label for="product_search">Product Search: </label>
      <input id="product_search" type="text" data-provide="typeahead">
    </div>

    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/bootstrap-typeahead.js"></script>

    <script>
      $(document).ready(function($) {
        // Workaround for bug in mouse item selection
        $.fn.typeahead.Constructor.prototype.blur = function() {
          var that = this;
          setTimeout(function () { that.hide() }, 250);
        };

        $('#product_search').typeahead({
          source: function(query, process) {
            return ["Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter"];
          }
        });
      });
    </script>
  </body>
</html>

【问题讨论】:

  • 预输入有什么问题?

标签: jquery html css twitter-bootstrap bootstrap-typeahead


【解决方案1】:

问题在于您的“源”源应该是 JSON 对象列表。能改吗

    $('#product_search').typeahead({
      source: function(query, process) {
        return ["Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter"];
      }
    });

收件人:

$('#product_search').typeahead({
    source: [
        {id: 1, name: 'Deluxe Bicycle'},
        {id: 2, name: 'Super Deluxe Trampoline'},
        {id: 3, name: 'Super Duper Scooter'}
    ]
});

告诉我它是否有效:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多