简体   繁体   中英

Navigate between text fields using javascript and two arrows icons

I'm looking to make 2 arrows (Up & Down buttons). Both are .gif. the thing is:

I have form with 4 text fields. How do I make it so that when I click the Down button.gif I navigate to the next text field then if press again I navigate to another field, and if I press Up button.gif to navigate up to the previous field like with a keyboard using arrows but instead using 2 images up & down.

How have to be the javascript function for this?

If you add the attribute tabindex to the different input fields you can access them with document.querySelector('input[tabindex="1"]') (replace 1 with current field tabindex) and call .focus() on them.

Basic example: http://jsfiddle.net/xc2n7/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM