Home > Web Front-end > JS Tutorial > jquery-based text box combined with autocomplete (asp.net json)_jquery

jquery-based text box combined with autocomplete (asp.net json)_jquery

WBOY
Release: 2016-05-16 17:53:05
Original
890 people have browsed it

JS script reference

Copy code The code is as follows:



Style Reference
Copy the code The code is as follows:



JS code
Copy Code The code is as follows:

?$(document).ready(function () {
$("#<%=_SearchKeyGame.ClientID %> ;").autocomplete("./AjaxHandle/AutoComplete.ashx?type=game", {
minChars: 0,
max: 9,
width: 150,
matchContains: true,
autoFill: false,
formatItem: function (row, i, max) {
return row.name;
},
formatMatch: function (row, i, max) {
return row.name " ";
},
formatResult: function (row) {
return row.name;
}
});
jQuery("#<% =_SearchKeyGame.ClientID %>").result(function (event, data, formatted) {
if (data) {
jQuery("#_SearchKeyGame").attr("value", data.name) ;
}
else {
}
});
$("#<%=_SearchKeyPlat.ClientID %>").autocomplete("./AjaxHandle/AutoComplete.ashx ?type=plat", {
minChars: 0,
max: 9,
width: 150,
matchContains: true,
autoFill: false,
formatItem: function (row , i, max) {
return row.name;
},
formatMatch: function (row, i, max) {
return row.name " ";
},
formatResult: function (row) {
return row.name;
}
});

AutoComplete. ashx returns JOSON value
Copy code The code is as follows:

string queryStr = context.Request.QueryString ["q"];
context.Response.ContentType = "text/plain";
context.Response.Cache.SetNoStore();
string jsponString = "[";
string where = string.Format(" (select dbo.[f_GetPy](platname)) like '%{0}%' or platname like '%{0}%'", Common.Common.ToSql(queryStr));
DataTable dt = new Models.Plat().GetDataTable(where,10);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows .Count; i )
{
jsponString = "{id:"" dt.Rows[i]["PlatID"].ToString() "",name:"" dt.Rows[i][" PlatName"].ToString() ""},";
}
}
jsponString = jsponString.Trim(new char[] { ',' });
jsponString = "]";
context.Response.Write(jsponString);
context.Response.End();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template