javascript标签 - 它允许标签

时间:2016-03-08 16:25:19

标签: javascript jquery tag-it

我需要允许用户在tagSource中选择仅允许的标签。

目前我有:

var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
$("#myTags").tagit({
    tagSource: sampleTags 
});

tag-it in GitHub

Tag-it! Usage Examples

你能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

检查一下它是否可行

 var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
    $("#myTags").tagit({
        availableTags: sampleTags,
         afterTagAdded: function (event, ui) {
        if ($.inArray(ui.tagLabel, sampleTags) == -1) {
            $("#myTags").tagit("removeTagByLabel", ui.tagLabel);
        }
    }
    });