Home >Web Front-end >JS Tutorial >jquery.autocomplete modification to implement automatic filling of keyboard up and down keys example_jquery

jquery.autocomplete modification to implement automatic filling of keyboard up and down keys example_jquery

WBOY
WBOYOriginal
2016-05-16 17:14:041050browse

According to the requirements, it is necessary to move up and down through the keyboard to obtain the value in the Lenovo menu, just like the query function of Google Baidu.
I have been searching online for a long time but could not find a plug-in that can achieve this function, so I had no choice but to change the code myself.
Find the KEY.DOWN and KEY.UP execution codes in js
as follows:

Copy the code The code is as follows:

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

Add
Copy code The code is as follows:
var selected = select.selected();
var v = selected.result;
$input.val(v);

After adding this, there will be corresponding values ​​in the input box when pressing the up and down keys, but the cursor on the Lenovo keyboard will disappear.
Find select.next(); The definition of the code

Copy the code The code is as follows:
next: function() {
moveSelect(1);
},

Add a similar method

Copy Code The code is as follows:
stay: function() {
moveSelect(1);
},

Then

Copy the code The code is as follows:
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 to the original author,

Add a similar method

Copy the code The code is as follows:
stay: function() {
moveSelect(1);
}, and later found that clicking the up and down keys will move interlaced rows, so it was changed to:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn