twitter-bootstrap $(...).tagsinput 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37222144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:55:06  来源:igfitidea点击:

$(...).tagsinput is not a function

javascriptjquerytwitter-bootstrapbootstrap-tags-input

提问by aco

I must be missing something simple but I can't see it. I am using the Bootstrap tagsinput plugin and I am trying to follow some of the examples here: http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

我一定错过了一些简单的东西,但我看不到它。我正在使用 Bootstrap 标签输入插件,我试图按照这里的一些示例进行操作:http: //bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

Here is my code:

这是我的代码:

<html>
  <head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.min.js"></script>
  </head>
  <body>
    <input id="cities" class="form-control" value="New York,London" data-role="tagsinput" type="text">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script>
      $(function() {
        $('#cities').tagsinput({
          maxTags: 3
        });
      });
    </script>
  </body>
</html>

I am getting the following Javascript error:

我收到以下 Javascript 错误:

tagsinput.html:15 Uncaught TypeError: $(...).tagsinput is not a function

I tried removing data-role="tagsinput"as suggested in this SO answerbut the input becomes a regular textbox and the exception still occurs.

我尝试data-role="tagsinput"按照此 SO 答案中的建议删除,但输入变为常规文本框,并且仍然发生异常。

What am I doing wrong?

我究竟做错了什么?

回答by Ramanlfc

you're loading 2 jquery min files in your scripttags.

您正在script标签中加载 2 个 jquery min 文件。

remove the one after bootstrap-tagsinput.min.jsor since the 2nd one is newer version load that instead of the 1st one.

bootstrap-tagsinput.min.js在第二个之后或之后删除一个是较新的版本,而不是第一个。

http://jsbin.com/xarasebibi/edit?html,output

http://jsbin.com/xarasebibi/edit?html,输出

回答by lightup

You duplicated jquery links. one at the top and the other at the bottom. and the bootstrap-tag-min script has to be linked only after you have included jquery link. see below for more info. Hope that helps

您复制了 jquery 链接。一个在顶部,另一个在底部。并且只有在包含 jquery 链接后才必须链接 bootstrap-tag-min 脚本。请参阅下文了解更多信息。希望有帮助

<html>
  <head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.css" />
  </head>
  <body>
    <input id="cities" class="form-control" value="New York,London" data-role="tagsinput" type="text">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.min.js"></script>
    <script>
      $(function() {
        $('#cities').tagsinput({
          maxTags: 3
        });
      });
    </script>
  </body>
</html>