简体   繁体   English

Bootstrap 3 Typeahead无法与Bootstrap标签一起使用

[英]Bootstrap 3 typeahead not working with bootstrap tags

I'm following the tutorial from following link, bootstrap3-tutorial . 我正在从以下链接bootstrap3-tutorial跟踪该教程 Now in that link there is an example as below, 现在在该链接中有一个如下示例,

HTML code, HTML代码

<input type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo" data-role="tagsinput" />

jQuery code, jQuery代码

$('input').tagsinput({
  typeahead: {
    source: ['Amsterdam', 'Washington', 'Sydney', 'Beijing', 'Cairo']
  }
});

When I type 'S', it is expected that I get the suggestion 'Sydney', but the problem is I'm not getting any suggestions. 当我输入'S'时,预期会收到建议'Sydney',但问题是我没有得到任何建议。 Below are the files that I'm importing, 以下是我要导入的文件,

<link href="bootstrap3.min.css" rel="stylesheet">
        <link href="typeaheadjs.css" rel="stylesheet">    
    <script src="jquery.js"></script>
    <script src="bootstrap3.min.js"></script>
    <script src="typeahead.js"></script>

So why I'm not getting any suggestions? 那么,为什么我没有得到任何建议? You can also suggest me some other way through which I can generate suggestions for creating bootstrap tags. 您还可以通过其他方式向我提出建议,通过这些方式可以生成有关创建引导标记的建议。

You should remove data-role="tagsinput" , since you are calling the plugin directly. 您应该删除data-role="tagsinput" ,因为您是直接调用插件。

Also, add an Id to the input . 另外,在input添加一个ID。

So your should become: 因此,您应该成为:

<input type="text" id="id1" value="Amsterdam,Washington,Sydney,Beijing,Cairo" />

And use should change your jquery to: 并且使用应将您的jquery更改为:

$(function () {
    $('#id1').tagsinput({
        typeahead: {
            source: ['Amsterdam', 'Washington', 'Sydney', 'Beijing', 'Cairo']
        }
    });
});

This should work. 这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM