JavaScript implementation ecshop search box keyboard key switch control _javascript skills

Source: Internet
Author: User
Tags prev

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.