这是我的代码:
select: function (event, ui) {
if (ui.item.value != "Match not found") {
$(this).val(ui.item.value + "test");
} else {
$(this).val("");
}
}
从建议中选择一个元素后,我始终收到原始ui.item.value
。我从未收到ui.item.value
+“测试”值
答案 0 :(得分:0)
我认为$(this)并没有指向正确的对象。使用元素的类名而不是此。
答案 1 :(得分:0)
我遇到了这个问题。我忘了阻止显示所选元素的默认行为。实际上下面是解决方案。我不需要else语句,因为我使用选择所选元素的默认行为。
select: function (event, ui) {
if (ui.item.value == "Match not found") {
$(this).val("");
event.preventDefault();
}
}