gpt4 book ai didi

javascript - 使用 tagit 删除输入字段中的 tagLabel

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:30 25 4
gpt4 key购买 nike

我使用 https://github.com/aehlke/tag-it这个用于自动完成标记的插件

用户只需从现有数组sampleTags中取出标签

在添加标签之前我检查元素是否在数组中

beforeTagAdded: function(evt, ui) {  
var counter = jQuery.inArray(ui.tagLabel, sampleTags);

if (counter != -1 ) { return true; }
else { alert('This word is not in array'); return false; }
},

但输入的内容并没有被删除。

我该怎么做?

jsFiddle: http://jsfiddle.net/zqDXL/3/

最佳答案

试试这个:

if (counter != -1) {
return true;
} else {
alert('This word is not in array');
$('.tagit-new input').val('');
return false;
}

演示 here

关于javascript - 使用 tagit 删除输入字段中的 tagLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18547606/

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