【发布时间】:2021-01-07 21:03:40
【问题描述】:
这是我的 onclick 事件,每次我调用它时,我的 .autocomplete 都不起作用。解释会很有帮助
$('#txtRecipient').on('click', function () {
alert("Im being called");
//call another view
//$('#inboxModal').modal('show');
});
$(function () {
$("#txtRecipient").autocomplete({
source: function (request, response) {
$.ajax({
url: '/Send/AutoComplete/',
data: "{ 'username': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data, function (item) {
return {
label: item.UserName,
value: item.UserID
//+ "," + item.UserName,
};
}));
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
e.preventDefault();
$("#txtUserID").val(i.item.value);
$("#txtRecipient").val(i.item.label);
//alert(i.item.value);
},
minLength: 1
}).focus(function () {
//$(this).autocomplete("search");
});
});
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<input id="txtRecipient" type="text" />
【问题讨论】:
-
自动完成和模态都不是定义的函数。代码块中缺少导入?
-
@ShanerM13 对不起,我不明白你的意思,不过我会查一下。谢谢
-
@Ryan Wilson 先生,谢谢您的回答,但我的问题完全错误,我会编辑它。我想要的是能够从下拉列表中进行选择。我道歉
-
@LadySari 不客气。很高兴能提供帮助。
-
@LadySari 你能检查一下下面的 kblau 答案吗
标签: javascript jquery asp.net-mvc