JavaScript implementation Ecshop search box keyboard Toggle Control

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.

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

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.