这里是我的代码,有什么不对吗?
它似乎不显示焦点上的列表,我还是要按一个键之前,它显示列表
它似乎不显示焦点上的列表,我还是要按一个键之前,它显示列表
<link media="all" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> <script type="text/javascript"> $(function() { $('#id').autocomplete({ source: ["ActionScript","AppleScript","Asp","BASIC","C","C++","Clojure","COBOL","ColdFusion","Erlang","Fortran","Groovy","Haskell","Java","JavaScript","Lisp","Perl","PHP","Python","Ruby","Scala","Scheme" ],minLength: 0 }); }).focus(function(){ $(this).trigger('keydown.autocomplete'); }); </script> <input type="text" id="id">
解决方法
看起来你正在将focus()处理程序附加到匿名函数,而不是文本框。
尝试这个:
<script type="text/javascript"> $(function() { $('#id').autocomplete({ source: ["ActionScript",/* ... */ ],minLength: 0 }).focus(function(){ // The following works only once. // $(this).trigger('keydown.autocomplete'); // As suggested by digitalPBK,works multiple times $(this).data("autocomplete").search($(this).val()); }); }); </script>