2

我一定错过了一些简单的东西,但我看不到它。我正在使用 Bootstrap tagsinput 插件,我正在尝试遵循这里的一些示例:http: //bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

这是我的代码:

<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>

我收到以下 Javascript 错误:

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

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

我究竟做错了什么?

4

2 回答 2

7

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

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

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

于 2016-05-14T03:34:16.317 回答
0

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

<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>
于 2016-05-14T03:58:03.930 回答