基于jquery的文本框與autocomplete結(jié)合使用(asp.net+json)
更新時間:2012年05月30日 14:28:55 作者:
基于jquery的文本框與autocomplete結(jié)合使用示例代碼,需要的朋友可以參考下
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();
復制代碼 代碼如下:
<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();
相關(guān)文章
jquery+CSS3實現(xiàn)淘寶移動網(wǎng)頁菜單效果
這篇文章主要介紹了jquery+CSS3實現(xiàn)淘寶移動網(wǎng)頁菜單效果,實例分析了jquery操作頁面樣式動態(tài)變換及熱區(qū)的選擇技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08JQuery Ajax 異步操作之動態(tài)添加節(jié)點功能
異步操作動態(tài)添加節(jié)點,導致在代碼中給添加的節(jié)點全局綁定事件或者獲取元素無效,問題出在哪里呢?下文給大家介紹下,感興趣的朋友參考下吧2017-05-05Jquery選擇子控件"大于號"和" "區(qū)別介紹及使用示例
Jquery選擇子控件”>“:在給定的父元素下匹配所有的子元素;另一個就是在給定的祖先元素下匹配所有的后代元素,具體概述及使用示例如下,感興趣的朋友可以參考下哈2013-06-06BootStrap和jQuery相結(jié)合實現(xiàn)可編輯表格
這篇文章主要介紹了BootStrap和jQuery相結(jié)合實現(xiàn)可編輯表格的相關(guān)資料,需要的朋友可以參考下2016-04-04jQuery基礎(chǔ)知識點總結(jié)(DOM操作)
下面小編就為大家?guī)硪黄猨Query基礎(chǔ)知識點總結(jié)(DOM操作)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06jquery 設(shè)置style:display的方法
這篇文章主要介紹了jquery 設(shè)置style:display的方法,需要的朋友可以參考下2015-01-01