2

自动完成部分有效,但单击下拉列表中的值只会将它们放入搜索框中,然后我必须按 Enter 来执行搜索。如何获取要搜索的值?

<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

<script>
  $(function() {
    var availableTags = [
      "SEO",
      "Responsive Design",
      "Google Local",
      "Twitter",
      "Social Media",
      "Web Design",
      "What is Google Authorship",
      "NFL",
      "Fantasy Football Rankings",
      "Kevin Sullivan",
      "Fantasy Football RB Rankings 2013",
      "Fantasy Football",
      "How to Buy Twitter Followers",
      "Advanced IFX",
      "Social Media Marketing",
      "NFL Schedule 2013-2014 Season",
      "Fantasy Football Breakdown",

    ];
    $(".search_box").autocomplete({
  source: availableTags,
  select: function(event, ui) { 
    $(".search_box").val(ui.item.value);
    $("#search").submit();
    });
  });
  </script>
4

2 回答 2

1

我想这就是你要找的:

$(".search_box").autocomplete({
  source: availableTags,
  select: function(event, ui) { 
    $(".search_box").val(ui.item.value);
    $("form").submit();
  }
})

更改“表单”以选择您为搜索提交的特定表单。这将使用您单击的任何值填充搜索框,然后自动提交搜索表单。

这是一个可用于测试的 jsfiddle:http: //jsfiddle.net/4gArf/

于 2013-06-10T16:51:18.167 回答
0

如该属性所示,documentationsource属性可以指向将返回数据的远程端点:

<script type="text/javascript">
    $('.search_box').autocomplete({
        source: '/remote.php'
    });
</script>
于 2013-06-10T07:17:51.870 回答