2017-10-06 34 views
0

我已经添加了一个搜索下拉菜单与jQuery。它工作正常,当我输入不匹配的数据时,显示not match消息。但是,当我选择其中一个下拉项目,然后通过删除某些字符进行更新时,not match不会显示。怎么可能做到这一点?Jquery自动完成验证程序

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

您的代码工作正常,如果您从列表中匹配一些单词,然后删除最后一个字符它仍将匹配词,因为是和自动完成......,只要它包含了一些潜台词它将被匹配..

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">

+0

是有可能做这样的网站https://www.montway.com/quote?本网站有两个自动完成输入字段,当我想在选择下拉字段后更改任何文本时,它将删除文本。 – rayan005