【问题标题】:Typeahead in Bootstrap Tags input plug in not workingBootstrap Tags 输入插件中的 Typeahead 无法正常工作
【发布时间】:2013-11-29 12:06:16
【问题描述】:

我正在尝试在一个小型测试应用程序中使用引导标记输入 (http://timschlechter.github.io/bootstrap-tagsinput/examples/)。我想使用 typeahead 功能,但似乎无法让它工作。在我看来,一切都井井有条,但我似乎无法让预先输入的内容正常工作。请注意,我在 Django 中使用它 - bootstrap.min.js 加载到我的 base.html 文件中。我是 jquery 的新手,所以我确定我在脚本中搞砸了。

{% extends "base.html" %}

{% block title %}Testing{% endblock %}
{% block extra_head %}

    <link href="{{STATIC_URL}}css/snippets.css" rel="stylesheet">
    <script src="{{STATIC_URL}}js/bootstrap-tagsinput.js"></script>
    <link href="{{STATIC_URL}}css/bootstrap-tagsinput.css" rel="stylesheet">


<script>
     $('#tagtest').tagsinput({
        typeahead: {
        source: ['Amsterdam','Denver']
        }
      });
</script>
    {% endblock %}


{% block base_content %}

<input id ="tagtest" data-role="tagsinput" type="text"  value="Amsterdam,Washington"/>

{% endblock %}

任何想法将不胜感激/ TJS

【问题讨论】:

  • 如果有任何错误,您能告诉我们吗?
  • 另外你用的是哪个版本的bootstrapbootstrap tags
  • 没有报错,只是缺少预输入。输入被正确格式化为标签,看起来很棒,但没有建议。对于 Bootstrap,我使用的是 2.32 版,而对于 bootstrap 标签,我在代码中看不到版本,但我使用了我最初帖子中链接中的下载。我没有使用为 Bootstrap V3 发布的版本
  • 其实我能弄明白。我把脚本放在页面的顶部。我把它放在输入的正下方,它根据需要工作。我对 Jquery 了解得不够多,无法理解为什么 - 但我会在这一点上接受它并回头阅读原因。
  • 我认为你应该用.ready() 包装你的内联脚本,并且头部版本应该也可以工作。

标签: jquery django twitter-bootstrap bootstrap-typeahead


【解决方案1】:

对于任何在使用 Bootstrap 2.x 时努力让 typeahead 工作的人:如果你通过它的 id 将 tagsinput 附加到你的输入元素,比如:

$('#tagtest').tagsinput({...});

然后不要在您的输入元素上设置 data-role="tagsinput"

【讨论】:

    【解决方案2】:

    如果您使用的是 bootstrap 3,这可能是正常的,因为 typeahead 已被删除。 添加这个typeahead js文件Link to typeahad version which works with bootstrap 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      相关资源
      最近更新 更多