jquery - 仅标记AvalaibleTags 选项不起作用

标签 jquery asp.net-mvc-3 tag-it

我使用 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 : trueallowNewTags: 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/

相关文章:

javascript - 在 Asp.Net MVC Razor 中将 HTML View 作为电子邮件附件发送

asp.net-mvc-3 - 通过 URL 将 DateTime 传递到 Controller 导致 ASP .NET MVC 3 中出现错误(区域性)

asp.net-mvc-3 - 如何将外部 CSS 应用于 Html Helper 类元素?

jQuery 标记它! - 如何更改焦点边框

php - 将 tagit 输入数据拆分为多行

javascript - 从单独页面加载的 JQuery UI 对话框中的 Google 图表

jquery - 从 jQuery 调用 ASP.NET 4.0 WCF 服务会产生 400 Bad Request

javascript - jQuery 隐藏和显示胜过 CSS 媒体查询

asp.net-mvc-3 - Visual Studio web dev express 挂起添加 Entity Framework

jQuery tag-it 只允许来自自动完成源的标签