js实例教程-基于jquery的文本框与autocomplete结合使用(asp.net+json)

发布时间:2018-11-24 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-基于jquery的文本框与autocomplete结合使用(asp.net+json)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

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();

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();

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦!&nbsp;js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-基于jquery的文本框与autocomplete结合使用(asp.net+json)全部内容,希望文章能够帮你解决js实例教程-基于jquery的文本框与autocomplete结合使用(asp.net+json)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。