我添加了一个带有jquery的搜索下拉菜单。当我输入不匹配的数据时,它可以正常显示not match
消息。但是,当我选择其中一个下拉项目然后通过删除一些字符来更新它时,not match
将无法显示。怎么可能呢?
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
$("#tags").autocomplete({
source: aTags.concat(bTags),
response: function(e, result) {
if (!result.content.length) {
console.log('No matches!');
jQuery('#messag').html("Not match...").show();
} else {
jQuery('#messag').hide();
}
}
});
答案 0 :(得分:0)
你的代码按预期工作,如果你匹配列表中的某个单词,然后删除它仍将匹配单词的最后一个字符,因为它是和自动完成...,只要它包含一些子文本它将匹配..
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
$("#tags").autocomplete({
source: aTags.concat(bTags),
response: function(e, result) {
console.log(result);
if (!result.content.length) {
console.log('No matches!');
jQuery('#messag').html("Not match...").show();
} else {
jQuery('#messag').hide();
}
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<input id="tags">
&#13;