make enter key作为Textbox上的Tab键

时间:2012-09-26 06:38:36

标签: jquery asp.net

如何使 Enter 键作为 Tab 键 使用jQuery在asp.net中的一个文本框?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

 <script type="text/javascript">
     $(document).ready(function () {

         var inputs = $(':input').keypress(function (e) {
             if (e.which == 13) {
                 e.preventDefault();
                 var nextInput = inputs.get(inputs.index(this) + 1);
                 if (nextInput) {
                     nextInput.focus();
                 }
             }
         });

     });                                    
 </script>     
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" TabIndex="3"></asp:TextBox>

    </div>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:5)

$("input").bind("keydown", function(event) {
    if (event.which === 13) {
        event.stopPropagation();
        event.preventDefault();
        $(this).next("input").focus();
    }
});
相关问题