Javascript jQuery UI自动完成-在按下/按下键后访问输入的搜索词
如何访问用户输入的搜索词 我读过,但不明白 例如,用户在“sna”中键入,并获得包含自动完成候选项的菜单:Javascript jQuery UI自动完成-在按下/按下键后访问输入的搜索词,javascript,jquery,jquery-ui,jquery-ui-autocomplete,Javascript,Jquery,Jquery Ui,Jquery Ui Autocomplete,如何访问用户输入的搜索词 我读过,但不明白 例如,用户在“sna”中键入,并获得包含自动完成候选项的菜单: 蛇 抢夺 金鱼 用户按下键,自动完成输入字段立即填充“snake” 此时,我想得到输入字段“sna”的上一个原始值 我如何才能做到这一点?(以编程方式,无需按ESC键)。您可以使用$.ui.autocomplete.escapeRegex(req.term) 它就像一个符咒,你是如何找到这个解决方案的?我的意思是,你怎么知道它在escapeRegex中?我阅读并找到了函数escapeR
- 蛇
- 抢夺
- 金鱼
我如何才能做到这一点?(以编程方式,无需按ESC键)。您可以使用
$.ui.autocomplete.escapeRegex(req.term)代码>
它就像一个符咒,你是如何找到这个解决方案的?我的意思是,你怎么知道它在escapeRegex中?我阅读并找到了函数escapeRegex
。
var wordlist= [ "about", "above", "across", "after", "against",
"along", "among", "around", "at", "before",
"behind", "below", "beneath", "beside", "between"] ;
$("#input1").autocomplete({
// The source option can be an array of terms. In this case, if
// the typed characters appear in any position in a term, then the
// term is included in the autocomplete list.
// The source option can also be a function that performs the search,
// and calls a response function with the matched entries.
source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
alert(re); //THIS IS WHAT YOU WANT
var matcher = new RegExp( "^" + re, "i" );
var a = $.grep( wordlist, function(item,index){
return matcher.test(item);
});
responseFn( a );
}
});