使用 jQuery UI 插件 Tag-it ,可以输入包含 100 个字符的标签,例如:
“loremipsumdolorsitametconsecteturadipisicingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliquautenimadminimveniamquisnostrudexeritationullamco”
我正在尝试设置每个标签允许的最大字符数。到目前为止,我已经尝试过 tagLimit
但这限制了允许的标签总数,但没有限制每个标签的字符限制。
有谁知道如何设置每个标签允许的字符数限制?
$(document).ready(function() {
$("#tags").tagit({
tagLimit: 5,
allowSpaces: true,
placeholderText: 'Tags'
});
});
最佳答案
我知道这不是最好的解决方案,但我编辑了 _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);
},
关于jquery - jQuery UI 插件 Tag-it 中每个标签允许的最大字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130505/