In the Createselect () function, returns an object, two methods of this object, next ()
and the Moveselect () of the Call in Prev () can correctly point to the function, or you can
The Moveselect () function is put outside.
The
code is as follows:
///keyboard operation and problem recommendation options * *
var curdo = null;
var select = Createselect ();
$ (' #keywords '). KeyUp (function (e) {
var theevent = e | | window.event;
code = Theevent.keycode? Theevent.keycode: (Theevent.which. TheEvent.which:theEvent.charCode)
var KEY = {
up:38,
down:40,
del:46,
Tab:9,
Return:13,
esc:27,
Backspace:8,
left:37,
right:39
};
cleartimeout (Curdo)//keyboard bounce time should cancel timed Ajax fetch data Operation
switch (code) {
case KEY. Up:
Select.next ();
break;
case KEY. Down:
Select.prev ();
break;
case KEY. return:
$ ('. Suggest-hover '). Trigger (' click ');
break;
case KEY. Left:
break;
case KEY. Right:
break;
Default:
Curdo = settimeout (Getsuggest (), 300);
break;
}
});
/* Suggest select operation * *
function Createselect () {
var CLASSES = {
ACTIVE: "Suggest-hover"
};
function Moveselect (step) {
var listitems=$ ('. Suggest-results li ');
//Current hover steps
var active;
active = $ ('. ' +classes. ACTIVE). index ();
Listitems.eq (Active). Removeclass (CLASSES. ACTIVE);
Active + = step;
if (Active < 0) {
active = Listitems.size ()-1;
else if (active >= listitems.size ()) {
active = 0;
}
var activeitem = Listitems.eq (active). addclass (CLASSES. ACTIVE);
};
return {
next:function () {
Moveselect (-1);
},
prev:function () {
Moveselect (1);
}
};
};
The above is the entire content which this article shares to everybody, hoped everybody can like