2013-06-11 61 views
1

我正在尝试使用jQuery UI自动完成插件创建类似于Google的网站搜索。如何使用jQuery UI自动完成插件进行搜索?

当有人搜索自动完成时辅助搜索。这部分工作在我的网站上(图片):http://www.advancedifx.com/

问题是,如果你点击下拉选择,在我选择的图像示例中:搜索引擎优化,但所有点击做的是把文本进入搜索框,然后你必须按回车。我需要获得选择来执行搜索的帮助。

请注意,我的Javascript技能是初学者的杠杆,并花了三天的时间才得到这一点。如果您认为您可以提供帮助,请准确告诉我需要修改的位置和内容。

预先感谢

enter image description here

$(function() { 
var availableTags = [ 
    "SEO", 
    "Responsive Design", 
    "Google Local", 
    "Twitter", 
    "Social Media", 
    "Web Design", 

]; 
$(".search_box").autocomplete({ 
    source: availableTags 
}); 

});

回答

0

综观API:http://api.jqueryui.com/autocomplete/#event-select

您可以访问select事件。

$(".search_box").autocomplete({ 
    source: availableTags, 
    select: function(event, ui) { 
    console.log(ui); // you can see output of this in your dev console 

    var searchTerm = ui.item; // pretty sure item will give you what you want 

    // you can then trigger your button click or form submit (whatever you're doing) 
    // passing along the searchTerm 

    $('.top_bar_search').find('form').submit(); 
    } 
}); 
+0

我试着用你的建议,但没有去或我做错了什么。 [链接]” ' – user2469885

+0

您需要触发您的表单或搜索功能。 – Jack

+0

我不知道该怎么做? – user2469885

相关问题