如何在Jquery自动完成插件中显示默认建议?

时间:2015-12-09 06:26:07

标签: jquery jquery-autocomplete jquery-ui-autocomplete

我希望每当用户点击表单输入时,都会显示默认的选项列表,例如Refer practo

点击专业,医生诊所等。我该怎么做?

2 个答案:

答案 0 :(得分:0)

尝试类似this的内容:

$('.prod-filter-nav h4').on('click'

请参阅:https://stackoverflow.com/a/11168511/4613398

答案 1 :(得分:0)

$( "#tags" )
    .autocomplete({
        source: availableTags
    }).on('focus', function(){ $(this).autocomplete("instance").search("a"); } );

将代替"自动完成("搜索")" 完整代码低于

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.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
    }).on('focus', function(){ $(this).autocomplete("instance").search("a"); } );

  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Anshu: </label>
  <input id="tags";>
</div>


</body>
</html>