我想显示由focus()事件触发的自动完成列表,但看起来它只适用于我第一次关注“id”文本框,然后我专注于“id2”文本框,并重点关注“id”文本框,我的自动完成列表将不会显示,任何原因?
<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
});
$('#id').focus(function(){
$(this).trigger('keydown.autocomplete');
});
});
</script>
<input type="text" id="id">
<input type="text1" id="id2">
我想显示由focus()事件触发的自动完成列表,但看起来它只适用于我第一次关注“id”文本框,然后我专注于“id2”文本框,并重点关注“id”文本框,我的自动完成列表将不会显示,任何原因?
<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
});
$('#id').focus(function(){
$(this).trigger('keydown.autocomplete');
});
});
答案 0 :(得分:3)
尝试使用
$(本).autocomplete( “搜索”)
而不是
$(本).trigger( 'keydown.autocomplete')
答案 1 :(得分:0)
这样做
<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
}).on("focus", function () {
$(this).autocomplete("search", '');
});
});
</script>
答案 2 :(得分:0)
尝试使用
$(this).autocomplete(“ search”,$(this).val())
代替
$(this).autocomplete(“ search”)
并制作
minLength:1