当前位置:嗨网首页>书籍在线阅读

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>