【发布时间】:2012-06-17 02:27:07
【问题描述】:
我使用 jquery ui 来实现自动完成。我的代码是这样的
$(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 中,我发现输入的元素自动完成属性设置为关闭。这就是我的代码不起作用的原因。请指导我
【问题讨论】:
-
你为什么使用这个
#inpuut[name=store]我认为这个应该是$('input[name=store]')或$('#inpuut') -
在这行
$('#inpuut[name=store]').attr('autocomplete','on');中将inpuut的拼写更改为input。此外,如果您从localhost获取数据,则应使用json而不是jsonp。 -
我认为你不需要这行代码
('#inpuut[name=store]').attr('autocomplete','on');jQuery 自动完成会做所有事情 -
抱歉输入错误。 @Imdad 我包括在内,因为我观察到 atuocomplete 属性被设置为我的输入字段并且它的值是关闭
标签: php jquery autocomplete