11-在输入框获得焦点时显示建议列表
9.5.3 在输入框获得焦点时显示建议列表
下面是上一段脚本的修改版。此时当用户单击输入框时,建议列表会立即浮现。这时候,当输入框获得焦点(focus)时,就会显示搜索列表项了:
<script src = jquery.js></script>
<script src = jqueryui/js/jquery-ui-1.8.16.custom.min.js></script>
<link rel=stylesheet type=text/css
href=jqueryui/css/smoothness/jquery-ui-1.8.16.custom.css />
<h3>Enter the name of the book:</h3>
<input id=book />
<script>
// 建议列表中待匹配的数组项
var books = ["Web development with J2EE", "Practical CSS & JavaScript",
"Practical Ruby on Rails", "Introduction to HTML & CSS",
"jQuery UI"];
$("input#book").autocomplete ({
source : books,
minLength : 0
}).focus (function (event)
{
$(this).autocomplete ("search", "");
});
</script>