【发布时间】:2020-04-01 08:45:55
【问题描述】:
我的测试用例中的html部分是
<div class="typeahead__container">
<div class="typeahead__field">
<div class="typeahead__query">
<input class="txtSearchProduct" id="txtSearchProduct" autocomplete="off" tabindex="8">
</div>
</div>
</div>
</div>
在使用这个jquery typeahad 库时, 像这样... (demo's here)
$.typeahead({
input: '.txtSearchProduct',
minLength: 0,
maxItem: 15,
order: "asc",
hint: true,
href: "",
searchOnFocus: true,
emptyTemplate: 'No results found "{{query}}"',
display: ["id", "code", "name", "table"],
template: "{{name}}<small style='color:#999;'>{{code}}</small>",
source: {
"Products": {
ajax: {
url: "/search/product",
path: ""
}
}
},
callback: {
onClickAfter: function (node, a, item, event) {
//debugger;
event.preventDefault;
//$("#txtSearchProduct").val("");
$.ajax({
type: "POST",
url: "/controller/add/" + item.id,
success: function (data) {
},
error: function (data) {
},
done: function () {
$("#loading").hide();
}
});
}
},
debug: true
});
我在选择后清除输入时遇到问题。
在回调事件中我尝试使用清除值
$('#txtSearchProduct').typeahead('val', '');
甚至与
$('.typeahead').typeahead('txtSearchProduct', '');
但其中任何一个都按预期工作。似乎在选择输入时引发的事件不再引发。
更新
在使用$("#txtSearchProduct").val("") 时,输入被清除,但它再次部分工作,除非我点击关闭按钮。
【问题讨论】:
-
您不只是清除输入吗?
$("#txtSearchProduct").val("")? -
你能检查一下更新吗?
标签: jquery typeahead.js typeahead