3

Using the jQuery UI plugin Tag-it, it is possible to enter tags with 100s of characters such as:

"loremipsumdolorsitametconsecteturadipisicingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliquautenimadminimveniamquisnostrudexercitationullamco"

I'm trying to set a maximum number of characters allowed per tag. So far I have tried tagLimit but this limits the total number of tags allowed but not the character limit for each tag.

Does anyone know how I could set a limit to the number of characters allowed per tag?

$(document).ready(function() {
    $("#tags").tagit({
        tagLimit: 5,
        allowSpaces: true,
        placeholderText: 'Tags'
    });
});
4

1 回答 1

0

我知道这不是最好的解决方案,但我编辑了 _cleanedInput 方法以将每个标签最多剪切为 100 个字符(在我的应用程序中,我怀疑任何标签都会超过 100 个字符,甚至不会接近 50 个字符!)。

在插件中,我改变了这个:

_cleanedInput: function() {
    return $.trim(this.tagInput.val().replace(/^"(.*)"$/, '$1'));
},

至:

_cleanedInput : function() {
    return $.trim(this.tagInput.val().replace(/^"(.*)"$/, "$1")).substr(0, 100);
},
于 2015-12-10T18:57:47.653 回答