Javascript 垂直聚焦于文本框

Javascript 垂直聚焦于文本框,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我需要通过按enter键在垂直方向上聚焦文本框 第一排,第二排,第三排 这是我的剧本 $(文档).ready(函数(){ $(“.vertical_row1”)。按键(功能(事件){ 如果(event.keyCode==13){ 文本框=$(“input.vertical_row1”); 调试器; currentBoxNumber=textboxs.index(此); if(文本框[currentBoxNumber+1]!=null){ nextBox=文本框[currentBoxNumber

我需要通过按enter键在垂直方向上聚焦文本框

第一排,第二排,第三排

这是我的剧本

$(文档).ready(函数(){
$(“.vertical_row1”)。按键(功能(事件){
如果(event.keyCode==13){
文本框=$(“input.vertical_row1”);
调试器;
currentBoxNumber=textboxs.index(此);
if(文本框[currentBoxNumber+1]!=null){
nextBox=文本框[currentBoxNumber+1]
nextBox.focus();
nextBox.select();
event.preventDefault();
返回错误
}
}
});
})

试试tabIndex


(函数($){
$.fn.formNavigation=函数(){
$(此)。每个(函数(){
//按键时触发的事件(按住键时可重复)
$(this).find('input')。on('keydown',函数(e){
//需要使用选项卡进行垂直导航
if(e.which==13&&!e.shiftKey){
//向前航行
if($(this).closest('tr').next().find('input').length>0){
//当下面还有一排的时候
e、 预防默认值();
$(this).closest('tr').next().children().eq($(this).closest('td').index()).find('input').focus();
}else if($(this).closest('tbody').find('tr:first').children().eq($(this).closest('td').index()+1).find('input').length>0){
//当最后一排到达时
e、 预防默认值();
$(this).closest('tbody').find('tr:first').children().eq($(this).closest('td').index()+1).find('input').focus();
}
}else if(e.which==13&&e.shiftKey){
//向后导航
if($(this).closest('tr').prev().find('input').length>0){
//当上面还有一排的时候
e、 预防默认值();
$(this).closest('tr').prev().children().eq($(this).closest('td').index()).find('input').focus();
}else if($(this).closest('tbody').find('tr:last').children().eq($(this).closest('td').index()-1).find('input').length>0){
//当第一排到达
e、 预防默认值();
$(this).closest('tbody').find('tr:last').children().eq($(this).closest('td').index()-1.find('input').focus();
}
}
});
});
};
})(jQuery);
//用法
$('.gridexample').formNavigation()

    <table>
        <tr>
            <td><input tabindex="0" class="vertical_row1" type="text" name="" value="" placeholder=""></td>
            <td><input tabindex="2" class="vertical_row2" type="text" name="" value="" placeholder=""></td>
        </tr>
        <tr>
            <td><input tabindex="1" class="vertical_row1"  type="text" name="" value="" placeholder=""></td>
            <td><input tabindex="3" class="vertical_row2" type="text" name="" value="" placeholder=""></td>
        </tr>
    <table>