jQuery UI自动完成自动关闭 [英] jquery ui autocomplete is automatically turned off
本文介绍了jQuery UI自动完成自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
im使用jquery ui实现自动完成. mY代码看起来像这样
im using jquery ui to achieve autocomplete. mY code looks like this
$(function(){
$('input[name=store]').attr('autocomplete','on');
$( "input[name=store]" ).autocomplete({
source: function( request, response ) {
//alert('hello');
$.ajax({
url: "http://localhost/dheeps/admin/calls/callback.php",
dataType: "jsonp",
data: {
sub:"searchstore",
store: request.term
},
success: function( data ) {
//alert('hello');
response( $.map( data.data, function( item ) {
//alert(item);
return {
label: item.name + (item.id1 ? ", " + item.adminName1 : "") + ", " + item.id,
value: item.id
}
}));
}
});
},
minLength: 2,
select: function( event, ui ) {
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
//alert('helo');
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
然后在表单的html中,我发现输入的元素autocomplete属性设置为off.这就是为什么我的代码无法正常工作的原因.请指导我
And the in the html of the form I found the input's element autocomplete attribute set to off. Is this why my code is not working. Please guide me
推荐答案
放在下面
$('input[name=store]').attr('autocomplete','on');
此后
$( "input[name=store]" ).autocomplete({});
因为autocomplete
属性将在初始化后添加到元素.
Because autocomplete
attribute will added to element after initialization.
这篇关于jQuery UI自动完成自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文