jQuery插件之AutoComplete使用方法
来源:互联网 发布:网页机器人源码 编辑:程序博客网 时间:2024/05/08 15:15
http://files.cnblogs.com/jianjialin/jquery.autocomplete.js
http://files.cnblogs.com/jianjialin/jquery.autocomplete.css
public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(getProducts(context)); } private string getProducts(HttpContext context) { string sql = "select * from products"; string re = JsonHelper.ConvertDataTableToJson(SqlHelper.ExecuteDataSet(sql).Tables[0]); return re; }
<script type="text/javascript"> /*==========用户自定义方法==========*/ //城市数据 var cityList; //autocomplete选项 var options = { minChars: 1, max: 500, width: 250, matchContains: true, formatItem: function(row, i, max) {//显示出来的项格式 return i + "/" + max + ": /"" + row.ProductID + "/" [" + row.ProductName + "]"; }, formatMatch: function(row, i, max) { return row.ProductName; //用户输入的内容在哪些数据项里面搜索。例如现在是在productName搜索,若要加上ProductID则为 return row.productID+" "+ row.ProductName; }, formatResult: function(row) { return row.ProductName; } }; //autocomplete初始化函数 function initAutoComplete(json) { $("#inputName").autocomplete(json, options); $("#inputName").result(function(event, data, formatted) {//data 选中的行json对象. formatted是formatMatch返回的值. $("#inputId").val(data.ProductID); }); } /*==========加载时执行的语句==========*/ $(function() { //加载城市数据, 并在回调函数中用返回的数据初始化autocomplete $.getJSON("products.ashx", {}, function(json) { initAutoComplete(json); }) }); </script> <link href="jquery.autocomplete.css" rel="stylesheet" type="text/css" /></head><body><div class="ui-widget ui-widget-content ui-corner-all" style="width: 700px; padding: 5px;"> <h3> Demo. 应用AutoComplete插件 </h3> <br style="clear: both" /> <div class="formLabel"> <label for="inputName">请输入城市拼音和汉字:</label> </div> <div class="formInput"> <input id="inputName" name="inputName" type="text" /> </div> <br style="clear:both" /> <br style="clear: both" /> <div class="formLabel"> <label for="inputId">城市ID:</label></div> <div class="formInput"> <input id="inputId" name="inputId" type="text" /></div> <br style="clear: both" /> <br style="clear: both" /> </div></body>
StationAjax.ashx
public class StationAjax : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
context.Response.Write(getProducts());
}
private string getProducts()
{
string re = JsonHelper.ConvertDataTableToJson(StationDa.GetTable());
return re;
}
public bool IsReusable
{
get
{
return false;
}
}
}
JsonHelper
public static string ConvertDataTableToJson(DataTable dt)
{
StringBuilder JsonString = new StringBuilder();
//Exception Handling
if (dt != null && dt.Rows.Count > 0)
{
JsonString.Append("[ ");
for (int i = 0; i < dt.Rows.Count; i++)
{
JsonString.Append("{ ");
for (int j = 0; j < dt.Columns.Count; j++)
{
if (j < dt.Columns.Count - 1)
{
JsonString.Append(dt.Columns[j].ColumnName.ToString() + ":" + "/"" + dt.Rows[i][j].ToString() + "/",");
}
else if (j == dt.Columns.Count - 1)
{
JsonString.Append(dt.Columns[j].ColumnName.ToString() + ":" + "/"" + dt.Rows[i][j].ToString() + "/"");
}
}
/**/
/*end Of String*/
if (i == dt.Rows.Count - 1)
{
JsonString.Append("} ");
}
else
{
JsonString.Append("}, ");
}
}
JsonString.Append("]");
return JsonString.ToString();
}
else
{
return null;
}
}
- jQuery插件之AutoComplete使用方法
- Jquery插件之Autocomplete
- jQuery插件之Autocomplete
- jquery自动补全插件autocomplete的使用方法之autocomplete ajax获取数据展示
- jquery.autocomplete.js使用方法
- jquery 插件 autocomplete
- jquery插件autocomplete
- Jquery插件autocomplete
- jQuery 插件autocomplete 应用
- jQuery 插件autocomplete 应用
- jquery插件autocomplete
- jQuery 插件autocomplete 应用
- jQuery 插件autocomplete 应用
- jQuery 插件autocomplete 应用
- Jquery autocomplete插件使用
- jQuery 插件autocomplete 应用
- jQuery 插件autocomplete 应用
- jQuery Autocomplete插件
- 文本编辑器 分页 分析图表控件
- DLL高级技术
- 自适应编码实现
- gwt 设置国际化
- 高级SQL生成选项的两个总是灰色
- jQuery插件之AutoComplete使用方法
- linux 下V4L的使用例子
- 网站优化之title、keywords、description标签写法
- 解决live555支持real player通过rtp-over-tcp访问问题
- java生成登录验证码的方法
- python中socket编程出现的no route to host问题。
- ServletContext与ServletConfig的深度分析
- 俄罗斯
- 快速排序算法(降序-C++)