我有一个具有自动完成功能的文本框。
从自动完成列表中选择数据,然后在输入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"); });
});
}
最佳答案
选择自动完成值时,文本框KeyDown
事件将以keyCode
13触发。
要检测何时选择了列表中的项目,可以执行以下操作:
Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = 13 Then
MsgBox("Autocomplete value selected")
End If
End Sub
关于asp.net - 如何触发自动完成文本框的文本更改事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23385645/