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