📜  jQuery UI autocomplete

📅  最后修改于: 2020-11-27 01:55:15             🧑  作者: Mango

jQuery UI自动完成

自动填充机制在现代网站中经常使用,可在文本框中键入起始单词时向用户提供建议列表。它方便用户从列表中选择一个项目,该项目将显示在输入字段中。此功能可防止用户输入整个单词或一组单词。

jQueryUI提供了一个自动完成小部件,通过在文本框中提供一系列建议来方便用户。这个控件的行为很像元素必须作为输入字段进行管理,该字段将显示在建议列表上方。这里的options参数是一个对象,它指定当用户在输入字段中键入内容时建议列表的行为。

句法:

$(selector, context).autocomplete (options);

您可以使用JavaScript对象一次使用一个或多个选项。如果有多个选项,则必须使用逗号将它们分开,如下所示:

$(selector, context).autocomplete({option1: value1, option2: value2..... });

以下是可与该方法一起使用的不同选项的列表:

Option Description
appendTo This option is used append an element to the menu. By default its value is null.
autoFocus If you set this option as TRUE, the first item of the menu will automatically be focused when the menu is shown. By default its value is FALSE.
delay This option specifies the time delay in milliseconds to wait before trying to obtain the matching values (as specified by the source option). By default its value is 300.
disabled If you set this option as true, the autocomplete widget is initially disabled. By default its value is false.
minlength It specifies the number of characters that must be entered before trying to obtain the matching values (as specified by the source option). By default its value is 1.
position This option identifies the position of the suggestions menu iaccording to the input element. By default its value is { my: “left top”, at: “left bottom”, collision: “none” }.
source This option specifies the manner in which the data that matches the input data is obtained. You must have to provide a value or the autocomplete widget won?t be created. By default its value is none; must be specified.

jQuery UI autocomplete()示例1

让我们以一个简单的示例来演示自动完成小部件功能,不向autocomplete()方法传递任何参数。




  
  jQuery UI Autocomplete - Default functionality
  
  
  
  
  


Available Courses:

jQuery UI autocomplete()方法示例2

在jQueryUI中使用autoFocus autocomplete()方法:

让我们以一个示例来演示自动完成方法中选项autoFocus的用法。




  
  jQuery UI Autocomplete - Default functionality
  
  
  
  
  


 

jQuery UI autocomplete()方法示例3

在jQueryUI中使用minLength和delay的autocomplete()方法:

让我们以一个示例来演示jQueryUI autocomplete()方法中两个选项minLength和delay的用法。




  
  jQuery UI Autocomplete - Default functionality
  
  
  
  
  


Type two letter for e.g:ja,sc etc

Available Courses:

jQuery UI autocomplete()方法示例4

在jQueryUI中使用lable autocomplete()方法:

让我们以一个示例来演示jQueryUI的自动完成小部件中选项标签的用法:



   
      
      jQuery UI Autocomplete functionality
      
      
      
      
      
   
   
       
      

Type I OR A