我有一个jquery自动完成功能,并选择带有id的成员名称。我在调用select事件时获取所选成员id,如下所示:
//For autocomplete extender generating members
$(function () {
$('.tags').autocomplete({
//make ajax call to get all members
source: function (request, response) {
$.ajax({
self.memberOptions(data.d);
});
}
},
select: function (event, ui) {
self.selectedMemberId(ui.item.value); //selected memberid
}
})
.keypress(function (e, data, ui) {
if (e.which == 13) {
//selected memberid when pressing enter key
//self.selectedMemberId(ui.item.value); //selected memberid
}
});
});
在select事件中我得到了成员的id,我想在自动完成的按键事件中获得memberId。
答案 0 :(得分:0)
$('.tags').keypress(function (e)
{
e.preventDefault();
var memberId = $(e.target).val();
});