2017-10-06 36 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