zoukankan      html  css  js  c++  java
  • JQuery.AutoComplete自动完成

    <html>
    <head>
    <title></title>
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="jquery.autocomplete.js" type="text/javascript"></script>
    <link rel="Stylesheet" type="text/css" href="jquery.autocomplete.css" />
    <script type="text/javascript">          
           // var test = [ "程序","程序员", "天", "天气", "Google", "Good", "csdn"];        
            $().ready(function() {  
               // $("#test1").autocomplete(test);   
                $("#test1").autocomplete("Handler.ashx",{autoFill: true}); 
            });  
    </script>

    </head>
    <body>
    <form id="form1">
      <input type="text" id="test1" />  
    </form>
    </body>
    </html>

    ===========================================================

    Handler.ashx

    <%@ WebHandler Language="C#" Class="Handler" %>

    using System;
    using System.Web;

    public class Handler : IHttpHandler {
       
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string result = "";

            if (context.Request.Params["q"] != null)
            {
                string key = context.Request.Params["q"];
                if (context.Cache.Get(key) != null)
                    result = context.Cache.Get(key).ToString();
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        result += key + i.ToString() + "\n";
                    }
                    context.Cache.Add(
                        key,
                        result,
                        null,
                        DateTime.Now.AddMinutes(3),
                        System.Web.Caching.Cache.NoSlidingExpiration,
                        System.Web.Caching.CacheItemPriority.Default,
                        null);
                }
                context.Response.Write(result);
            }
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }

    }

    ===========================================================

    存在问题: 在对中文输入法打开时, firefox 中是对中文拼音的自动匹配,而对输入后的中文无法及时触发匹配,导致延时才出现匹配的中文。

    上网搜索到的方法:

    说明一下为了支持中文输入,需要修改 jquery.autocomplete.js 文件的几个地方 , 在文件的 190 多行左右,加上如下代码:

    .bind( "input" , function () {

        // @hack by liqt:support for inputing  chinese characters  in firefox

        onChange(0, true );

        } )

    ===========================================================

    不是很清楚上面说的是哪个地方,花了几分钟,终于测试通过了,把jquery.autocomplete.js中的下面代码


    }).bind("flushCache", function() {
            cache.flush();

    修改为

    }).bind("input", function() {
             onChange(0, true);
             }).bind("flushCache", function() {
            cache.flush(); 

  • 相关阅读:
    HttpUtils 用于进行网络请求的工具类
    Java 身份证工具类
    MD5加密Java工具类
    Nginx配置文件详细说明
    java统计abacbacdadbc中的每个字母出现的次数,输出格式是:a(4)b(3)c(3)d(2)
    mysql查询今天,昨天,近7天,近30天,本月,上一月数据的SQL
    Java随机生成常用汉字验证码
    Google Kaptcha验证码的使用
    Linux查看CPU和内存使用情况
    myql导入导出命令
  • 原文地址:https://www.cnblogs.com/gdjlc/p/2086940.html
Copyright © 2011-2022 走看看