博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JQuery.AutoComplete自动完成
阅读量:2119 次
发布时间:2019-04-30

本文共 1969 字,大约阅读时间需要 6 分钟。

 

 

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

 

转载地址:http://zxzrf.baihongyu.com/

你可能感兴趣的文章
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 26. 数组中出现次数超过一半的数字
查看>>
剑指offer 27.二叉树的深度
查看>>
剑指offer 29.字符串的排列
查看>>
剑指offer 31.最小的k个树
查看>>
剑指offer 32.整数中1出现的次数
查看>>
剑指offer 33.第一个只出现一次的字符
查看>>
剑指offer 34.把数组排成最小的数
查看>>
剑指offer 35.数组中只出现一次的数字
查看>>
剑指offer 36.数字在排序数组中出现的次数
查看>>
剑指offer 37.数组中重复的数字
查看>>
剑指offer 38.丑数
查看>>
剑指offer 39.构建乘积数组
查看>>
剑指offer 57. 删除链表中重复的结点
查看>>
剑指offer 58. 链表中环的入口结点
查看>>
剑指offer 59. 把字符串转换成整数
查看>>