2024年3月22日发(作者:)

jquery-autocomplete 使用手册

jquery-autocomplete学习

一、用前必备

官方网站:/jquery-plugins/jquery-plugin-autocomplete/

当前版本:1.0.2

需要JQuery版本:1.2.6

二、使用

autocomplete( url or data, options ) Returns: jQuery

让一个input或textarea有autocomplete功能

例子

Js代码

var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax

Utilities".split(" ");

$("#example").autocomplete(data);

以上的例子就是为id为example添加autocomplete

var emails = [

{ name: "Peter Pan", to: "peter@" },

{ name: "Molly", to: "molly@" },

{ name: "Forneria Marconi", to: "live@" },

{ name: "Master Sync", to: "205bw@" },

{ name: "Dr. Tech de Log", to: "g15@" },

{ name: "Don Corleone", to: "don@" },

{ name: "Mc Chick", to: "info@" },

{ name: "Donnie Darko", to: "dd@" },

{ name: "Quake The Net", to: "webmaster@" },

{ name: "Dr. Write", to: "write@" }

];

//emails的数组格式如上,formatItem代表的是显示的格式,formatMatch表示匹配的内容,

formatResult表示结果的内容

$("#suggest13").autocomplete(emails, {

minChars: 0,

width: 310,

matchContains: true,

autoFill: false,

formatItem: function(row, i, max) {

return i + "/" + max + ": "" + + "" [" + + "]";

},

formatMatch: function(row, i, max) {

return + " " + ;

},

formatResult: function(row) {

return ;

}

});

三、参数说明:

* minChars (Number):

在触发autoComplete前用户至少需要输入的字符数.Default: 1,如果设为0,在输入框内双

击或者删除输入框内内容时显示列表

* width (Number):