突出显示列表中不可用的标签

Highlight tags which is not available into the list

我在 Asp.net 中使用 jQuery UI 小部件 Tagit。代码工作正常,但我想突出显示列表中不可用的标签。

如果我的标签是

var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript']

并且我正在使用 sampleTags 中不可用的任何其他词 我如何用其他颜色突出显示这些标签。

我正在使用以下代码

JS:-

     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<link href="../CSS/jquery.tagit.css" rel="stylesheet" />
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
          <script src="../JavaScript/tag-it.js"></script>
        <link href="../CSS/tagit.ui-zendesk.css" rel="stylesheet" />
    <script>
    $(function () {
        $.ajax({
            url: 'UpdateSingImgKwds.aspx/GetKeywords',
            type: 'GET',
            datatype: "json",
            contentType: "application/json; charset=utf-8",
            success: function (res) {
                $('#singleFieldTags').tagit({
                    caseSensitive: false,
                    availableTags: res.d,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldNode: $('#txtCompKwds'),
                    beforeTagAdded: function (event, ui) {

                        if ((res.d).indexOf(ui.tagLabel.toLowerCase()) == -1) {
                            $(ui.tag).css('background', '#fff1b5')
                        }
                    }

                });

            },
            failure: function (err) {
                alert(err);
            }
        });


    });

CS码:-

 [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public static string[] GetKeywords()
    {
        List<string> lst = new List<string>();
        string queryString = "select * from KWD_Library ORDER BY Keyword asc";
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["vConnString"].ToString()))
        {
            using (SqlCommand command = new SqlCommand(queryString, connection))
            {
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {

                    while (reader.Read())
                    {
                        lst.Add(reader["Keyword"].ToString());
                    }
                }
            }
        }
        return lst.ToArray();

请提前帮我做this.Thanks

使用beforeTagAdded事件并比较添加到sampleTags,

的标签
beforeTagAdded: function (event, ui) {             
        if ($.inArray(ui.tagLabel,sampleTags) == -1) {
            $(ui.tag).css('background', 'red')
            //you can use `addClass()` here instead of .css()
        }
    }

Demo Fiddle


$("#singleFieldTags").tagit({
    availableTags: sampleTags,
    beforeTagAdded: function (event, ui) {             
        if ($.inArray(ui.tagLabel,sampleTags) == -1) {
            $(ui.tag).css('background', 'red')
        }
    }
});