jQuery AutoComplete部件

jQuery AutoComplete部件

描述

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

语法

使用自动完成的简单语法如下所示:

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

示例

以下是一个简单的示例,展示了Autocomplete的用法 –

<!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://www.tutorialspoint.com/jquery/jquery-3.6.0.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>

这将产生以下结果−

jQuery AutoComplete部件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程