【发布时间】:2020-11-26 06:51:32
【问题描述】:
编辑:如果我不在回调中使用tagsinput(),我只能调用tagsinput()
这还是个问题,因为我需要在回调中调用tagsinput()。
原创:
我还没有找到解决我问题的答案:
我正在尝试使用这个库:https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
我的 HTML 文件包括:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.js"></script>
<!-- Bootstrap CDN links -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="script.js"></script>
<select id="el" data-role="tagsinput" name="el" multiple ></select>
在 script.js 中(连接到多个 HTML 文件,但上面包含有问题的文件):
function addTagToInput() {
$('#el').tagsinput('add', 'item2');
}
在尝试调用addTagToInput() 后,我得到$(…).tagsinput is not a function,即使正确加载了CDN JS 文件。
【问题讨论】:
-
你没有包含 jquery 库。
-
它包含在我的代码中,但它不在我的 sn-p 中。我的不好,会更新我的问题
-
不过,你需要在 tagsinput 之前包含 jquery。
-
啊,好的 - 我在我的代码中更改了它并更新了我的 sn-p。但是,重新运行后,我收到相同的错误消息。
-
将您的代码包装在 document.ready 处理程序中。 stackoverflow.com/questions/24930807/…查看最后的代码。
标签: javascript html jquery plugins