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.
Copy Code code 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 ');
The number of steps for the current hover
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