javascript jQueryUI 自动完成 - 选择后模糊字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6074000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQueryUI Autocomplete - blur field after selection
提问by Jesse
I would like to be able to blur the field after I select a value from the dropdown. I currently have the autocomplete item searching on focus.
从下拉列表中选择一个值后,我希望能够模糊该字段。我目前有自动完成项目搜索焦点。
Here is what I have:
这是我所拥有的:
$("#season").autocomplete({
source: function( request, response ) {
$.getJSON( "search.asp", {
term: request.term,
type: 'season'
}, response );},
minLength: 0
}).focus(function(event, ui){
$(this).autocomplete("search","");
});
回答by ShaneBlake
You could use the 'close' method to call blur on the input field:
您可以使用 'close' 方法在输入字段上调用模糊:
$("#season").autocomplete({
source: function(request, response){
$.getJSON("search.asp", {
term: request.term,
type: 'season'
}, response);
},
minLength: 0,
close: function(){
$(this).blur();
}}).focus(function(event, ui){
$(this).autocomplete("search", "");
});
回答by UpHelix
Autocomplete has a select event, which is triggered when you select something from the dropdown list. In that event you can call .autocomplete('close') on your input to close the dropdown.
自动完成有一个选择事件,当您从下拉列表中选择某些内容时会触发该事件。在这种情况下,您可以在输入中调用 .autocomplete('close') 以关闭下拉列表。
$("#season").autocomplete({
source: function(request, response){
$.getJSON("search.asp", {
term: request.term,
type: 'season'
}, response);
},
minLength: 0,
select: function(){
$(this).autocomplete('close');
}
}).focus(function(event, ui){
$(this).autocomplete("search", "");
});
Familiarizing yourself with the docs does wonders :)
熟悉文档确实很神奇:)
http://jqueryui.com/demos/autocomplete/
http://jqueryui.com/demos/autocomplete/
The tabs below the example (options, events, methods, etc.), will give you all you need to know.
示例下方的选项卡(选项、事件、方法等)将提供您需要了解的所有信息。
EDIT:
编辑:
Try this, works for me but I only tested in Chrome, FF3 and IE8.
试试这个,对我有用,但我只在 Chrome、FF3 和 IE8 中测试过。
$("#season").autocomplete({
source: function(request, response){
$.getJSON("search.asp", {
term: request.term,
type: 'season'
}, response);
},
minLength: 0,
select: function(){
$('#season').autocomplete('close').blur();
}
}).click(function(event, ui){
$(this).autocomplete("search", "");
});
Typically, using click instead of focus isn't a great idea.
通常,使用单击代替焦点并不是一个好主意。
回答by jocken
Found the solution for me. You have to trigger the blur and close on the "change".
为我找到了解决方案。您必须触发模糊并关闭“更改”。
$("#season").autocomplete({
source: function( request, response ) {
$.getJSON( "search.asp", {
term: request.term,
type: 'season'
}, response );},
minLength: 0,
change: function (event, ui) {
$(this).autocomplete('close').blur();
}
}).focus(function(event, ui){
$(this).autocomplete("search","");
});