官网文档:Autocomplete
1. autofocus:当智能提示框出现时,是否自动选中第一项,默认为false,即不选中。
// Getter
var autoFocus = $( ".selector" ).autocomplete( "option", "autoFocus" );
// Setter
$( ".selector" ).autocomplete( "option", "autoFocus", true );
// Getter
var delay = $( ".selector" ).autocomplete( "option", "delay" );
// Setter
$( ".selector" ).autocomplete( "option", "delay", 500 );
3. disabled:是否禁用自动完成功能,默认为false。
// Getter
var disabled = $( ".selector" ).autocomplete( "option", "disabled" );
// Setter
$( ".selector" ).autocomplete( "option", "disabled", true );
// Getter
var minLength = $( ".selector" ).autocomplete( "option", "minLength" );
// Setter
$( ".selector" ).autocomplete( "option", "minLength", 0 );
// Getter
var source = $( ".selector" ).autocomplete( "option", "source" );
// Setter
$( ".selector" ).autocomplete( "option", "source", [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ] );
6. appendTo :将值赋值给指定对象
// Getter
var appendTo = $( ".selector" ).autocomplete( "option", "appendTo" );
// Setter
$( ".selector" ).autocomplete( "option", "appendTo", "#someElem" );
7. position(还没有过) :
// Getter
var position = $( ".selector" ).autocomplete( "option", "position" );
// Setter
$( ".selector" ).autocomplete( "option", "position", { my : "right top", at: "right bottom" } );
创建Autocomplete初始化:
$( ".selector" ).autocomplete({
appendTo: "#someElem",
autoFocus: true
,
delay: 300,
disabled: true,
minLength: 0,
source:data
});
1. close():关闭智能提示选择框。
$( ".selector" ).autocomplete( "close" );
$( ".selector" ).autocomplete( "destroy" );
$( ".selector" ).autocomplete( "disable" );
4. enable():开启自动完成功能。
$( ".selector" ).autocomplete( "enable" );
5.instance() : 检索完成的实例对象。如果元素没有关联的实例,则返回未定义的。不像其他的部件的方法,instance()安全调用任何元素后,自动完成插件加载。
$( ".selector" ).autocomplete( "instance" );
6.option() : 获取包含键/值表示当前对象的哈希对(key/value)自动完成选项。
var options = $( ".selector" ).autocomplete( "option" )
7 .option( optionName ) :获取与指定optionname目前关联的值。
var isDisabled = $( ".selector" ).autocomplete( "option", "disabled" );
8.option( optionName, value ) :设置与指定的optionname相关的自动完成选项的值
$( ".selector" ).autocomplete( "option", "disabled", true );
9.option( options ) :设置一个或多个选项的自动完成。
10.search( [value ] ):触发一个搜索事件,如果事件没有被取消,则调用该数据源。可以通过selectbox像按钮用来打开建议点击时。当调用无参数时,使用当前输入的值。可以被称为一个空字符串,最大长度:0显示所有项目。
$( ".selector" ).autocomplete( "search", "" );
11.widget() :返回一个包含菜单元素的jQuery对象()
$( ".selector" ).autocomplete( "widget" );
1. change(event, ui):当值改变时发生,ui.item为选中的项。
$( ".selector" ).on( "autocompletechange", function( event, ui ) {} );
$( ".selector" ).on( "autocompleteclose", function( event, ui ) {} );
$( ".selector" ).on( "autocompletecreate", function( event, ui ) {} );
$( ".selector" ).on( "autocompletefocus", function( event, ui ) {} );
$( ".selector" ).on( "autocompleteopen", function( event, ui ) {} );
$( ".selector" ).on( "autocompleteresponse", function( event, ui ) {} );
7. search(event, ui):在开始请求之前发生,可以在此事件中返回false来取消请求。
$( ".selector" ).on( "autocompletesearch", function( event, ui ) {} );
$( ".selector" ).on( "autocompleteselect", function( event, ui ) {} );
$( ".selector" ).autocomplete({
change: function( event, ui ) {//方法 },
close: function( event, ui ) { //方法 },
create: function( event, ui ) {//方法 },
focus: function( event, ui ) {//方法 }
});