DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> 基於jquery的文本框與autocomplete結合使用(asp.net+json)
基於jquery的文本框與autocomplete結合使用(asp.net+json)
編輯:JQuery特效代碼     
JS腳本引用
. 代碼如下:
<script src="/scripts/Jquery.autocomplete/jquery.autocomplete.js" type="text/javascript"></script>

樣式引用
. 代碼如下:
<style type="text/css" media="all">
@import url("/scripts/Jquery.autocomplete/css/jquery.autocomplete.css");
</style>

JS代碼
. 代碼如下:
?$(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返回JOSON值
. 代碼如下:
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();
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved