我的测试案例中的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("")
时,输入将被清除,但是除非我单击关闭按钮,否则输入将再次部分起作用。