我不确定我是否正确理解了您的问题。延迟选项是击键发生与执行 ajax 搜索之间的延迟。您提供的代码将正确执行此操作。
我不确定您必须再按一个键是什么意思。执行按键后,自动完成将显示匹配的项目列表。您可以将 autoFocus 设置为 true,这将为您选择列表中的第一项。请参见下面的示例。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Jquery UI Auto complete</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
</head>
<body>
<div class="ui-widget">
<label for="tags">
Tags:
</label>
<input id="tags" />
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script type="text/javascript">
$(function ()
{
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$('#tags').autocomplete({
source: availableTags,
delay: 1000,
autoFocus: true
});
});
</script>