如何使用Enter键专注于下一个输入 [英] How to use enter key to focus into next input

查看:91
本文介绍了如何使用Enter键专注于下一个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下Enter键时,我希望它进入下一个输入,我已经看到了另一个问题的代码

when i hit enter key i want it to go to next input, i've seen a code from another question here but my input fields are inside the table, it won't work if my next input is on the next td here's my html code

<form action="#">
<table>
<thead>
    <tr>
    <th>Input 1</th>
    <th>Input 2</th>
    <th>Input 3</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>
            <input name="one"/>        
        </td>
        <td>
            <select name="select">
                <option>asd</option>
                <option>asd</option>
            </select>
           <input name="two"/> 
           <input name="three"/> 
        </td>
        <td>
           <input name="four"/>
        </td>
    </tr>
            <tr>
        <td>
            <input name="field-one"/>        
        </td>
        <td>
            <select name="select">
                <option>asd</option>
                <option>asd</option>
            </select>
           <input name="field-two"/> 
           <input name="field-three"/> 
        </td>
        <td>
           <input name="field-four"/>
        </td>
    </tr>
</tbody>
</table>

http://jsfiddle.net/k2y7evzr/

请帮我:)谢谢!

推荐答案

如何使用 index 属性,

$("input,select").bind("keydown", function(event) {
    if (event.which === 13) {
        alert("asd");
        event.stopPropagation();
        event.preventDefault();
       $(':input:eq(' + ($(':input').index(this) + 1) +')').focus();
    }
});

这篇关于如何使用Enter键专注于下一个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆