我使用 https://github.com/aehlke/tag-it/downloads 中的 tag-it 插件。如何禁止添加新标签?
$(document).ready(function () {
$("#Tags").tagit({
singleField: true,
singleFieldNode: $('#mySingleField'),
// onlyAvailableTags : true,
allowNewTags: false,
tagSource: [@Html.Raw(ViewBag.AvailableTags)]
});
});
我尝试使用 onlyAvailableTags : true
和 allowNewTags: false
选项,但没有效果。
最佳答案
我通过注释发现:
// Autocomplete will create its own tag from a selection and close automatically.
if (!that.tagInput.data('autocomplete-open')) {
that.createTag(that._cleanedInput());
}
还有:
// Create a tag when the element loses focus.
// If autocomplete is enabled and suggestion was clicked, don't add it.
if (!that.tagInput.data('autocomplete-open')) {
that.createTag(that._cleanedInput());
}
它删除了此功能。也许不是最干净的方法,但它确实有效。
只需注释掉 if(){ }
循环即可。
关于jquery - 仅标记AvalaibleTags 选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396369/