Posted on 2008-12-13 09:41
G_G 阅读(1105)
评论(1) 编辑 收藏 所属分类:
javascript
官方上下
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
$.补全中文 修改
jquery.autocomplete.js 中
$input.bind(($.browser.opera ? "keypress" : "keydown")
改为
$input.bind(($.browser.opera ? "keypress" : "
keyup")
$. 在 localdata.js 》》 var cities = [..
中放些 中文 测试吧
测试页面 ,最简单的使用页面 。(应该算是最简单补全测试了)
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
$("#suggest1").autocomplete([
"test1",
"test2",
"测试1",
"测试2"
]);
});
</script>
<input type="text" id="suggest1" />
使用json
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../jquery.autocomplete.js'></script>
<script type='text/javascript' src='localdata.js'></script>
<link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />
<script type="text/javascript">
var emails = [
{ name: "Peter Pan", to: "peter@pan.de" },
{ name: "Molly", to: "molly@yahoo.com" },
{ name: "Forneria Marconi", to: "live@japan.jp" },
{ name: "Master <em>Sync</em>", to: "205bw@samsung.com" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "g15@logitech.com" },
{ name: "Don Corleone", to: "don@vegas.com" },
{ name: "Mc Chick", to: "info@donalds.org" },
{ name: "Donnie Darko", to: "dd@timeshift.info" },
{ name: "Quake The Net", to: "webmaster@quakenet.org" },
{ name: "Dr. Write", to: "write@writable.com" }
]
$().ready(function() {
$("#suggest13").autocomplete(emails, {
//补全中选择显示
formatItem: function(row, i, max) {
return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
},
//补全匹配格式
formatMatch: function(row, i, max) {
return row.name ;
},
//补全选定后显示
formatResult: function(row) {
return row.to;
}
})
});
</script>