本文介绍了在asp.net c#中的jquery自动完成中突出显示匹配的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请您帮我突出显示自动完成文本框中的输入字词。我已经填充了自动完成的单词,我只需要单独突出显示单词。我是Jquery自动完成的新手。



我的代码是:



Could you please help me in highlighting the typed words in the auto complete text box. i am already populating the auto-complete words and i need to just highlight the typed words alone.i am new to Jquery auto-complete.

My code is:

<script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });
    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Default.aspx/GetAutoCompleteData",
                    data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response(data.d);

                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
            }
        });
    }
</script>







 [WebMethod]
public static List<string> GetAutoCompleteData(string username)
{
    List<string> result = new List<string>();
    using (SqlConnection con = new SqlConnection("Data Source=192.168.10.120;Initial Catalog=StockImageBank2014Apr;User ID=sa;password=sib"))
    {
        using (SqlCommand cmd = new SqlCommand("select top (10) SubCategory from PhotographySubCategory where SubCategory LIKE '%'+@SearchText+'%'", con))
        {
            con.Open();
            cmd.Parameters.AddWithValue("@SearchText", username);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                result.Add(dr["SubCategory"].ToString());
            }
            return result;
        }
    }
}

推荐答案









 [WebMethod]
public static List<string> GetAutoCompleteData(string username)
{
    List<string> result = new List<string>();
    using (SqlConnection con = new SqlConnection("Data Source=192.168.10.120;Initial Catalog=StockImageBank2014Apr;User ID=sa;password=sib"))
    {
        using (SqlCommand cmd = new SqlCommand("select top (10) SubCategory from PhotographySubCategory where SubCategory LIKE '%'+@SearchText+'%'", con))
        {
            con.Open();
            cmd.Parameters.AddWithValue("@SearchText", username);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                result.Add(dr["SubCategory"].ToString());
            }
            return result;
        }
    }
}


这篇关于在asp.net c#中的jquery自动完成中突出显示匹配的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:06