【问题标题】:Hide autocomplete box in Tag-it在 Tag-it 中隐藏自动完成框
【发布时间】:2016-05-24 13:32:46
【问题描述】:

我的页面上有一个 tagit 元素:

$("#myTags").tagit({
    fieldName: "tags",
    availableTags: availableTags,
    showAutocompleteOnFocus: true,
    allowSpaces: true
});

当我使用此代码添加标签时:

$("#myTags").tagit("createTag", tag);

当我点击输入然后点击外部时,自动完成框会弹出并隐藏!

我试图通过代码来模拟这个,但没有任何反应:

$(".ui-widget-content.ui-autocomplete-input").focus().blur();

【问题讨论】:

    标签: jquery jquery-ui tag-it


    【解决方案1】:

    我也遇到了这个问题,终于找到解决办法了!

    var tagElement = $("#myTags").tagit({
        fieldName: "tags",
        availableTags: availableTags,
        allowSpaces: true,
    
        /* you need to set these three options hide autocomplete after setting a tag */
        showAutocompleteOnFocus: true,
        beforeTagAdded: function (event, ui) {
            // turn autocomplete off
            tagElement.tagit('option', 'showAutocompleteOnFocus', false);
        },
        afterTagAdded : function(event, ui) {
            // turn autocomplete back on
            setTimeout(function () { tagElement.tagit('option', 'showAutocompleteOnFocus', true); }, 5);
        }
    });
    

    这是有效的,因为如果您将 showAutocompleteOnFocus 选项设置为 true,则 tagit 代码设置为在添加标签后自动显示自动完成。因此,我们暂时将其设置为 false,然后 5 毫秒后,我们将其重新打开。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      相关资源
      最近更新 更多