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

后端 未结 3 733
闹比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 22:48

    This is my final working code:

    $('input[type="text"],textarea').keydown( function(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    
        if(key == 40) {
            e.preventDefault();
            var inputs = $(this).parents('form').find(':input[type="text"]:enabled:visible:not("disabled"),textarea');
    
            inputs.eq( inputs.index(this)+ 1 ).focus();
            inputs.eq( inputs.index(this)+ 1 ).click();
        }
    });
    

提交回复
热议问题