use*_*532 4 php jquery autocomplete
我使用jquery ui来实现自动完成.mY代码看起来像这样
$(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" );
}
});
});
Run Code Online (Sandbox Code Playgroud)
并且在表单的html中我发现输入的元素autocomplete属性设置为off.这是我的代码不起作用的原因.请指导我
放在下面
$('input[name=store]').attr('autocomplete','on');
Run Code Online (Sandbox Code Playgroud)
在这之后
$( "input[name=store]" ).autocomplete({});
Run Code Online (Sandbox Code Playgroud)
因为autocomplete属性将在初始化后添加到元素.
| 归档时间: |
|
| 查看次数: |
7765 次 |
| 最近记录: |