当前位置: 首页 > 文档资料 > jQuery 入门教程 >

Autocomplete

优质
小牛编辑
139浏览
2023-12-01

描述 (Description)

Widget AutoComplete函数可以与JqueryUI中的小部件一起使用。自动完成小部件在您输入字段时提供建议。假设将Ja作为输入,它将提供输出为Java或JavaScript。

语法 (Syntax)

以下是使用自动完成的简单语法 -

$( "#tags" ).autocomplete({
   source: availableTags
});

例子 (Example)

以下是一个显示自动填充功能使用的简单示例 -

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI Autocomplete - Default functionality</title>
      <link rel = "stylesheet" 
         href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
      </script>
      <script>
         $(function() {
            var availableTags = [
               "ActionScript",
               "AppleScript",
               "Asp",
               "BASIC",
               "C",
               "C++",
               "Clojure",
               "COBOL",
               "ColdFusion",
               "Erlang",
               "Fortran",
               "Groovy",
               "Haskell",
               "Java",
               "JavaScript",
               "Lisp",
               "Perl",
               "PHP",
               "Python",
               "Ruby",
               "Scala",
               "Scheme"
            ];
            $( "#tags" ).autocomplete({
               source: availableTags
            });
         });
      </script>
   </head>
   <body>
      <div class = "ui-widget">
         <label for = "tags">Tags: </label>
         <input id = "tags">
      </div>
   </body>
</html>