【发布时间】:2023-03-21 01:01:01
【问题描述】:
我有一个带有自动完成功能的文本框。
从自动完成列表中选择数据,然后在 Enter key press 上触发
文本更改事件。
但我想在选择数据时触发文本更改事件。
function abc(sender, args) {
$(function () {
$("#<%=txtNumber.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/Webservice.asmx/abc") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
async: false,
mustMatch: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('^')[0],
val: item.split('^')[1]
}
}))
},
error: function (response) {
},
failure: function (response) {
}
});
},
select: function (e, i) {
$("#<%=hdnNumber.ClientID %>").val(i.item.val);
if (i.item.val == "No Records Found") {
$("#<%=hdnNumber.ClientID %>").val(-1);
document.getElementById('<%=txtNumber.ClientID%>').value = "";
return false;
}
},
minLength: 0
}).bind('focus', function () { $(this).autocomplete("search"); });
});
}
【问题讨论】:
-
我确实有同样的问题。
-
在 asp.net 的情况下,将“文本框”中的 autopostback(Properties) 更改为 true,在 Windows 的情况下,将按键事件赋予自动完成列表而不是文本框。
-
@gkrishy:我已经尝试将 autopost back 属性设为 true,但没有成功。
-
你试过 ajax autocompleteextender 吗?如果没有,请向我们展示您的尝试。