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

  • 相关阅读:
    JRE、JDK和JVM之间的关系
    操作系统——CPU、计算机的构成
    为什么要用Java泛型
    【docker】 centos7 下 使用docker 安装 LNMP
    【docker】 centos7 安装docker
    【laravel5.6】 IlluminateDatabaseQueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
    【truffle】Error: `truffle init` no longer accepts a project template name as an argument.
    【宝塔面板】pm2 安装没反应问题
    【node.js】】MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。
    【git】 linux 环境安装git
  • 原文地址:https://www.cnblogs.com/gdjlc/p/2086940.html
Copyright © 2011-2022 走看看