gpt4 book ai didi

jquery - 限制 jQuery 中输入标签的数量

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

我一直在寻找一个 jQuery 自动建议标签(类似于 stackoverflow 标签输入)插件,它限制输入标签的数量(例如,不允许创建超过 5 个标签?)。如果有人知道这样的插件,或者是 kind enough to modify this code限制标签的数量,我将非常感激。

最佳答案

好的,对 Tag It 插件进行了更改...

首先打开插件js文件,找到is_new函数(朝文件底部)...

将整个函数替换为:

    function is_new (value){
var is_new = true;
var count = 0;
this.tag_input.parents("ul").children(".tagit-choice").each(function(i){
count++;
n = $(this).children("input").val();
if (value == n || count >= options.maxTags) {
is_new = false;
}
})
return is_new;
}

注意,我只添加了 count 变量并修改了循环中的 if 语句来检查 count 是否 >= 选项 maxTags

然后当你调用插件时,设置 maxTags 选项:

    $('#tagBox').tagit({
availableTags: '../Tag/GetTags',
maxTags: 5
});

简单!

关于jquery - 限制 jQuery 中输入标签的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4995717/

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