[英]How to get index of removed data on taginput
我正在使用 jquery.tagsinput.js 進行標簽輸入。 我想獲取已刪除數據的索引。 我做不到。我的代碼在下面,我該如何解決?
謝謝
<div class="control-group">
<label class="control-label col-md-12 col-sm-12 col-xs-12">Input Tags</label>
<div class="col-md-12col-sm-12 col-xs-12">
<input id="tags_1" type="text" name="category_properties" class="tags form-control"
value="<?php echo $getcategory['category_properties'];?>" on-tag-removed="" ; />
<div id="suggestions-container" style="position: relative; float: left; width: 250px; margin: 10px;"></div>
</div>
</div>
$(document).ready(function () {
$("#tags_1").tagsInput({
width: "auto",
onRemoveTag: () => {},
});
});
嘗試搜索結果,並獲取找到的索引
$('#tags_1').tagsInput({
width: 'auto',
onChange: function(elem, elem_tags)
{
$('.tag', elem_tags).each(function()
{
if($(this).value==elem.get(0).value)
alert($(this).index() );
});
}
});
刪除數據的價值只是
$('#tags_1').tagsInput({
width: 'auto',
onChange: function(elem, elem_tags)
{
alert( "I removed this: " + elem.get(0).value);
}
});
也可以是移除數據的值
刪除的數據在onRemove
回調中提供。
onRemoveTag: function(val) { },
示例片段:
$('#tag1').tagsInput({ onRemoveTag: function(val) { console.log("remove", val) console.log(this) } });
#wrapper { margin: 20px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-tagsinput/1.3.6/jquery.tagsinput.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-tagsinput/1.3.6/jquery.tagsinput.min.css"> <div id="wrapper"> <p>This is a basic tag input: <input id="tag1" value="alpha,beta,gamma" /> </p> </div>
該索引似乎沒有任何意義,您需要在刪除之前知道所有標簽的值並在刪除后進行比較。 如果您使用索引來獲取值,則為時已晚,因為該值已被刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.