程序笔记   发布时间:2022-05-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了基于jquery的文本框与autocomplete结合使用(asp.net+json)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Js脚本引用
复制代码@H_197_4@ 代码如下:

<script src="/scripts/Jquery.autocomplete/jquery.autocomplete.Js" type="text/JavaScript"></script>

样式引用
复制代码@H_197_4@ 代码如下:

<style type="text/CSS" media="all">
@import url("/scripts/Jquery.autocomplete/CSS/jquery.autocomplete.CSS");
</style>

Js代码
复制代码@H_197_4@ 代码如下:

?$(document).ready(function () {
$("#<%=_SearchKeyGame.ClIEntID %>").autocomplete("./AJAXHandle/autoComplete.ashx?type=game",{ @H_366_0@minChars: 0,@H_366_0@max: 9,
wIDth: 150,@H_366_0@matchContains: true,
autoFill: false,
formatItem: function (row,i,maX) {
return row.name;
},
formatMatch: function (row,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",
formatResult: function (row) {
return row.name;
}
});

autoComplete。ashx返回JOSON值
复制代码@H_197_4@ 代码如下:

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

大佬总结

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

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

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