在焦点事件上显示jquery ui自动完成列表

前端之家收集整理的这篇文章主要介绍了在焦点事件上显示jquery ui自动完成列表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这里是我的代码,有什么不对吗?
它似乎不显示焦点上的列表,我还是要按一个键之前,它显示列表
<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>
原文链接:https://www.f2er.com/jquery/184607.html

猜你在找的jQuery相关文章