自动完成部分有效,但点击下拉列表中的值只会将它们放入搜索框,然后我必须按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>
答案 0 :(得分:1)
我认为这就是你要找的东西:
$(".search_box").autocomplete({
source: availableTags,
select: function(event, ui) {
$(".search_box").val(ui.item.value);
$("form").submit();
}
})
更改“表单”以选择您要为搜索提交的特定表单。这将在搜索框中填入您点击的任何值,然后自动提交搜索表单。
这是一个可以用来测试的jsfiddle:http://jsfiddle.net/4gArf/
答案 1 :(得分:0)
如documentation
所示,source
属性可以指向将返回数据的远程端点:
<script type="text/javascript">
$('.search_box').autocomplete({
source: '/remote.php'
});
</script>