我正在使用jquery auotcomplete功能。我已将此应用于以特定id开头的所有文本框,并根据当前文本框值过滤响应。但是没有得到价值。以下是我的代码。
$("input[id^='TextBoxAssociate']").autocomplete(
{
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CreateEditRequest.aspx/GetEmpNames",
data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
dataType: "json",
success: function (data) {
response($.map(data.d, function (el) {
return {
label: el.EmpName,
value: el.EmpId
};
}));
},
error: function (result) {
alert("Error");
}
});
}
答案 0 :(得分:0)
$("input[id^='TextBoxAssociate']").autocomplete(
{
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CreateEditRequest.aspx/GetEmpNames",
data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
dataType: "json",
success: function (data) {
response($.map(data.d, function (el) {
return {
label: el.EmpName,
value: el.EmpId
};
}));
},
error: function (result) {
alert("Error");
},
select: function (event, ui) {
var label = ui.item.label;
var value = ui.item.value;
alert('Label : ' + label );
alert('Value : ' + value );
}
});
}