aspx页面

需要引用的文件:

<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.autocomplete.js"></script>

script:

<script type="text/javascript" language="javascript">

$().ready(function() {

$.ajax({         contentType: "application/json",

url: "AutoComplete.ashx",

dataType: "json",

success: function (msg) {

$("#reg_XIAOQU").autocomplete(msg, {

minChars: 1,                    //最少输入字条

max: 40,

autoFill: false,                //是否选多个,用","分开

mustMatch: false,               //是否全匹配, 如数据中没有此数据,将无法输入

matchContains: true,            //是否全文搜索,否则只是前面作为标准

scrollHeight: 220,

width: 200,

multiple: false,

formatItem: function (row, i, max) {                    //显示格式

return "<span>" + row.alladress + "</span>";                     },

formatMatch: function (row, i, max) {               //以什么数据作为搜索关键词,可包括中文,

return row.alladress;                     },

formatResult: function (row) {                      //返回结果

return row.alladress;                     }

}).result(function (event, data, formatted) {

alert(data.alladress);                     //根据最终返回的数据做处理

});         }     });

});

</script>

后台代码处理页AutoComplete.ashx:

using System;

using System.Web;

using System.Data;

using System.Collections.Generic;

using System.Web.Script.Serialization;

public class AutoComplete : IHttpHandler {

public void ProcessRequest (HttpContext context) {

context.Response.ContentType = "text/plain";

ServiceWS myWS = new ServiceWS();     //实例化数据操作类

string sql = "Select alladress From LIVINGAREA";

DataSet ds = myWS.GetDsFromSql(sql);

if (ds.Tables[0]!=null)          {

string data = DbHelper.DataTable2Json(ds.Tables[0]);

context.Response.Write(data);

context.Response.Flush();

context.Response.End();

}

}

public bool IsReusable {

get {             return false;         }

}

}

效果图:

AutoComplete的更多相关文章

  1. autocomplete的使用

    autocomplete使用分为本地调用方法和读取远程读取数据源的方法 (1)本地调用方法 <script src="Scripts/jquery-1.4.1.min.js" ...

  2. 原生js实现autocomplete插件

    在实际的项目中,能用别人写好的插件实现相关功能是最好不过,为了节约时间成本,因为有的项目比较紧急,没充分时间让你自己来写,即便写了,你还要花大量时间调试兼容性.但是出于学习的目的,你可以利用闲暇时间, ...

  3. jQuery ui autocomplete 与easyUI冲突解决办法(重命名ui的autocomplete 和menu部分)

    http://jqueryui.com/download/   UI定制只选autocomplete 会自动把依赖的menu模块也加入进来--然而easyUI也有自己的menu,于是就-- 折腾了好久 ...

  4. Bootstrap 中的 Typeahead 组件 -- AutoComplete

    Bootstrap 中的 Typeahead 组件就是通常所说的自动完成 AutoComplete,功能很强大,但是,使用上并不太方便.这里我们将介绍一下这个组件的使用. 第一,简单使用 首先,最简单 ...

  5. smartComplete——轻量级的autoComplete插件,开源

    项目后端觉得autoComplete响应略慢,于是花了两天时间写了这插件,基于jQuery 1.7+,仓库地址 https://github.com/VaJoy/smartComplete ,欢迎各种 ...

  6. Autocomplete 自动补全(Webform实战篇)

    开篇语 因为项目中需要用到一个自动补全的功能,功能描述: 需求一:新增收件人的时候,自动下拉显示出数据库中所有的收件人信息(显示的信息包括:姓名-收件地址-联系方式) 需求二:选中一个值得时候,分别赋 ...

  7. jQuery AutoComplete在AJAX UpdatePanel环境中PostBack之后无法工作

    前些日子,Insus.NET有实现<ASP.NET MVC使用jQuery实现Autocomplete>http://www.cnblogs.com/insus/p/5638895.htm ...

  8. jQuery AutoComplete 自动补全

    jQuery.AutoComplete是一个基于jQuery的自动补全插件.借助于jQuery优秀的跨浏览器特性,可以兼容Chrome/IE/Firefox/Opera/Safari等多种浏览器. 特 ...

  9. autocomplete="off" 不起作用

    首先来了解一下 表单自动填充的原理,当我们登录的时候,如果选择的记住登录密码,那么后续界面中如果有 <input type="text" name="field1& ...

随机推荐

  1. mongodb之使用explain和hint性能分析和优化

    当你第一眼看到explain和hint的时候,第一个反应就是mysql中所谓的这两个关键词,确实可以看出,这个就是在mysql中借鉴过来的,既然是借鉴 过来的,我想大家都知道这两个关键字的用处,话不多 ...

  2. JavaScript如何获取网页url中的参数

    我们可以自定义一个公共函数来实现网页url中的参数获取,返回的是一个数组 GetUrlRequest: function () { var url = decodeURI(location.searc ...

  3. 用C++开发Binder服务

    用C++来实现Binder服务比较麻烦,原因是没有AIDL的辅助,必须手工来写中间的代码. 首先写一个服务类ExampleServer的代码: class ExampleServer : public ...

  4. 极路由2(极贰)在OpenWrt下定制自己的ss服务

    默认刷入的OpenWrt带的ss, 只有ss-redir服务, 但是在实际使用中, 很多时候还是希望访问直接通过正常网关, 只有少部分访问需要通过ss, 所以希望能配置成为ss-local服务. 在保 ...

  5. mac下搭建redis环境

    一.redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有 ...

  6. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  7. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  8. RabbitMQ总结概念

    AMQP:一个提供统一消息服务的应用层标准高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计 http://www.diggerplus.org/archives/3110 AMQP ...

  9. c++多重继承

    可以在子类中通过基类名访问函数 // oj4.cpp : Defines the entry point for the console application.// #include "s ...

  10. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...