2012-01-09 71 views
2

我正在使用jQuery自动完成。这里是我的
HTML自动完成minChars属性

<input class="autocomplete_input"> 

JS

$(".autocomplete_input").autocomplete({ 
    source: autocompleteOptions 
}); 

// autocompleteOptions is a array which contains all values for autocomplete 

一切工作正常。我想要显示关于onFocus的所有建议。在Google上搜索了一些类似的问题之后,我发现了Autocomplete的minChars属性。我试过但仍然没有运气

$(".autocomplete_input").autocomplete({ 
    source: autocompleteOptions, 
    minChars:0 
});  

我该如何正确使用minChars

EDIT1:
我用这link。谢谢罗里。
在给定的链接我找不到minLength财产。
EDIT2:
我试图

$(".autocomplete_input").autocomplete({ minLength: 0, source: autocompleteOptions}); 

还是建议不显示在onFocus。我注意到的一个区别是,如果我键入任何字符,则会显示相应的结果,如果使用反斜杠删除该字符,则会显示所有建议。

回答

4

您使用的是jQuery UI Autocomplete

正确的参数会minLength

$(".selector").autocomplete({ minLength: 0, source: autocompleteOptions }); 
+0

是我使用的是相同的。如何同时定义'source'和'minChar/minLength'? – xyz 2012-01-09 11:44:32

+0

'.autocomplete {{minLength:0,source:“source here”});'如我更新的回答所示 – 2012-01-09 11:48:01

+0

我正在使用http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions。在这里,我可以看到'minChars' – xyz 2012-01-09 11:56:14

0

尝试使用focus事件并调用自动完成手动显示:

$(".autocomplete_input").autocomplete({ 
    source: autocompleteOptions 
}).focus(
    function() { 
     if (this.value == "") { 
       $(this).autocomplete('search', ''); 
      } 
     } 
    ); 
+0

谢谢。我认为更容易的选择将在那里。或者我会去为你的。 – xyz 2012-01-09 11:58:38

0

这里是jQuery的自动完成的文档页面: http://jqueryui.com/demos/autocomplete/

您正在寻找的选项是minLength

$(".autocomplete_input").autocomplete({ 
source: autocompleteOptions, 
minLength:0 
});  
+0

请检查我的编辑。 – xyz 2012-01-09 11:59:01

1

假设this是你使用的插件,试试这个:

$(".autocomplete_input").autocomplete(
    autocompleteOptions, 
    { minChars: 0 } 
}); 
+0

感谢您的链接。是的,我正在使用相同的。我试过你的建议,但得到错误'错误:this.source不是函数 源文件:http:// localhost:7009/portal/javascript/jquery-ui-1.8.10.custom.min.js 行:322 ' – xyz 2012-01-09 11:55:22

+0

请检查我的编辑。 – xyz 2012-01-09 12:05:26

1
 
/* 
* jQuery Autocomplete plugin 1.2.3 
* 
* Copyright (c) 2009 Jörn Zaefferer 
* 
* Dual licensed under the MIT and GPL licenses: 
* http://www.opensource.org/licenses/mit-license.php 
* http://www.gnu.org/licenses/gpl.html 
* 
* With small modifications by Alfonso Gómez-Arzola. 
* See changelog for details. 
* 
*/ 

in line 588 change this 

[[[ for (var i = q.length - 1; i >= options.minChars; i--) { ]]] 

for this 

[[[ for (var i = q.length - 1; i >= 0; i--) { ]]] 

相关问题