简体   繁体   English

Ajax jQuery自动完成功能-通过单击开始搜索

[英]Ajax jQuery Autocomplete Function - Start search by click

I have little problems with the Ajax autocomplete function of jQuery. jQuery的Ajax自动完成功能几乎没有问题。

You can find the search function here: http://s500691824.online.de/new/index.php/en/ . 您可以在这里找到搜索功能: http : //s500691824.online.de/new/index.php/en/ There is a search form input on this site. 该站点上有一个搜索表单输入。

When you type in for example "top" you will see there are some keywords appearing in the autocomplete list. 例如,当您输入“ top”时,您会看到在自动完成列表中出现了一些关键字。

Now you can select one of this entrys and then you have to click enter again to start the search. 现在,您可以选择其中一项,然后必须再次单击Enter以开始搜索。 But I need the function to start the search by clicking one of the autocomplete suggestions. 但是我需要通过单击自动完成建议之一来启动搜索的功能。

Here is my HTML Code: 这是我的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>';

And here the jquery: 而这里的jQuery:

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

Do you know how I can solve this? 你知道我该怎么解决吗?

$("#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(); 
     }
});

if you are using latest jquery, this should work 如果您正在使用最新的jQuery,这应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM