Focus the next input with down arrow key (as with the tab key)

后端 未结 3 724
闹比i
闹比i 2021-01-01 22:45

I have a huge entry form and fields for the users to input.

In the form user use tab key to move to next feild,there are some hidden fields and readonly textboxe

3条回答
  •  感情败类
    2021-01-01 23:14

    Using jQuery, you can do this :

    $('input, select').keydown(function(e) {
        if (e.keyCode==40) {
            $(this).next('input, select').focus();
        }
    });
    

    When you press the down arrow key (keyCode 40), the next input receives the focus.

    DEMO​

    EDIT :

    In Vanilla JS, this could be done like this :

    function doThing(inputs) {    
        for (var i=0; i

    Note that you'd probably want to map the up key too, and go to first input at last one, etc. I let you handle the details depending on your exact requirements.

提交回复
热议问题