Jquery. Autocomplete modification to implement the keyboard up and down key auto fill example


According to the requirements to achieve by moving up and down the keyboard, the value in the lenovo menu, just like Google baidu query function. Looking for a long time on the Internet did not find the plug-in can achieve this function, but had to change their own code. Find keydown and keyup in js to execute the code As follows:


case KEY.DOWN:
event.preventDefault();
if ( select.visible() ) {
select.next();
}
else {
onChange(0, true);
}
break;

In the select next (); After joining


var selected = select.selected();
var v = selected.result;
$input.val(v);

After such addition, when the up and down keys input box will have the corresponding value, but the lenovo keyboard cursor is missing. Find the select next (); Definition of code


next: function() {
moveSelect(1);
},

Add a similar method


stay: function() {
moveSelect(1);
},

then


case KEY.DOWN:
event.preventDefault();
if ( select.visible() ) {
select.next();
var selected = select.selected();
var v = selected.result;
$input.val(v);
select.stay();
}
else {
onChange(0, true);
}
break;

That’s it.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Thank you very much,

Add a similar method


stay: function() {
moveSelect(1);
}, After clicking the up and down key, I found that it was interlacing, so I changed it to:

stay: function() {
moveSelect(0);
},