gpt4 book ai didi

jquery - 未捕获的 TypeError : $(. ..).tagsinput 不是函数

转载 作者:行者123 更新时间:2023-12-01 01:31:30 24 4
gpt4 key购买 nike

我有一个搜索框和几个复选框。选中后,复选框中的值将被推送到搜索框中。

现在我想对插入搜索框中的每个字符串使用引导标签输入,使其看起来像标签,但我在标题中收到错误消息。

我使用标签输入是否错误?

$(document).ready(function () {
$checks = $(":checkbox");
$checks.on('change', function () {
var ingredient = $checks.filter(":checked").map(function (i, v) {
return this.id;
}).get().join(" ");
$('#SearchString').tagsinput(ingredient);
}).trigger('change');
});
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<link href="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"></script>


<input class="form-control" id="SearchString" data-role="tagsinput" name="SearchString" type="text" value="">

最佳答案

这是您修改后的代码片段:

$(document).ready(function () {
$checks = $(":checkbox");
$checks.on('change', function () {
$('#SearchString').tagsinput('removeAll');
$checks.filter(":checked").each(function( index ) {
$('#SearchString').tagsinput('add', this.value);
});
}).trigger('change');
});
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<link href="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"></script>


<input class="form-control" id="SearchString" data-role="tagsinput" name="SearchString" type="text" value="">

<div class="checkbox">
<label><input id="chk1" type="checkbox" value="ingredient1">ingredient 1</label>
</div>
<div class="checkbox">
<label><input id="chk2" type="checkbox" value="ingredient2">ingredient 2</label>
</div>
<div class="checkbox disabled">
<label><input id="chk3" type="checkbox" value="ingredient3">ingredient 3</label>
</div>

这里提供了一个改进的版本,使用对象而不是纯文本作为标签:https://jsfiddle.net/beaver71/v44mnn31/16/

在此示例中,当删除标签输入中的标签时,相关复选框中的该标签将被取消选中。

关于jquery - 未捕获的 TypeError : $(. ..).tagsinput 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47779971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com