2013-12-18 54 views
0

我对jQuery的Ajax自动完成功能没有什么问题。Ajax jQuery自动完成功能 - 点击开始搜索

您可以在这里找到搜索功能: http://s500691824.online.de/new/index.php/en/。 本网站有一个搜索表单输入。

当您输入例如“top”时,您会看到自动完成列表中出现了一些关键字。

现在您可以选择其中的一个,然后您必须再次单击输入才能开始搜索。 但我需要通过单击其中一个自动填充建议来开始搜索的功能。

这是我的HTML代码:

echo '<form method="post" action="" id="searchform">'; 
echo '<input id="search-searchword" class="inputbox suche-startseite" type="text" onfocus="if (this.value==\''.$search_text.'\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\''.$search_text.'\';" value="'.$search_text.'" size="20" maxlength="20" name="searchword">'; 
echo '<input type="hidden" value="search" name="search_send">'; 
echo '</form>'; 

而这里的jQuery:

jQuery('#search-searchword').autocomplete({ 
    lookup: keywords, 
    minChars:3, 
    onSelect: function (suggestion) { 
     jQuery('.autocomplete-suggestion').click(function(e) { 
      jQuery('#searchform').submit(); 
     }); 
    } 
}); 

你知道我怎么能解决这个问题?

回答

1
$("#search-searchword").autocomplete({ 
    source: keywords, 
    minLength: 3, 
    select: function(event, ui) { 
     $("#search-searchword").val(ui.item.label); //which ever u have name or label 
     $("#searchform").submit(); 
    } 
}); 

,如果你使用的是最新的jQuery,这应该工作

+0

我很抱歉,但是这并没有帮助。 我使用了您的代码,并将一行更改为$(“#search-searchword”)。val(ui.item.searchword); (我使用了输入字段的名称)。 但没有任何改变。 –