0
我正在使用smartautocomplete。当我搜索任何数据,并且在滚动中完美工作时,它工作正常。 现在我正在尝试当用户点击文本框,然后它会默认显示自动完成框,但我无法打开焦点上的默认自动完成。 我正在使用smartautocomplete.js。 我的代码如下:在文本框焦点上填充smartautocomplete
$(document).ready(function() {
//Input for testing purposes
$("#inp").smartautocomplete({
getDataFunc: getData,
pageSize: 15,
autoFocus: true,
focus: function (event, ui) {
event.preventDefault();
},
select: function (event, ui) {
event.preventDefault();
$('#inp').val(ui.item.label);
$('#inp1').val(ui.item.value);
//$('#<%=hdnUserID.ClientID%>').val(ui.item.id)
},
change: function (event, ui) {
}
}).focus(function() {
//what to write here so i can get default autocomplete value on focus
});
});
//Function the SA plugin called when data is needed.
//var getData = function (input, pageIndex, pageSize, callback) {
var getData = function (input, pageIndex, pageSize, callback) {
//In this example I use a WebMethod, but you can call anything from a local source to any web service.
//url: "../../../Base/BindStateMaster?pageSize=10&pageNum=1&CountryCode=" + ParentddlValue,
$.ajax({
type: "POST",
url: "../../../Base/BindCountryMasterAuto",
data: "{'input':'" + input + "','pageIndex':'" + pageIndex + "','pageSize':'" + pageSize + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
dataFilter: function (data) { return data; },
success: function (response) {
if (response) {
//alert(JSON.stringify(response));
//Data is assumed to be received in a {label: , value: , ...} form, as needed by jqueryUI autocomplete. Of course, if you change the _renderItem function, you are free to modify this as you want
response = $.map(response.Data, function (item) {
return {
label: item.text,
value: item.id
}
});
callback(response);
}
else callback();
}
});
}
感谢新,但我想这个也是,但仍自动完成未填充的焦点。我正在使用smartautocomplete。 – 2015-04-06 14:59:12
和您提到的代码将适用于自动填充插件。我正在使用http://www.codeproject.com/Articles/325719/JQueryUI-smartAutocomplete – 2015-04-06 15:06:07