2012-09-26 98 views
0

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> 

回答

4
$("input").bind("keydown", function(event) { 
    if (event.which === 13) { 
     event.stopPropagation(); 
     event.preventDefault(); 
     $(this).next("input").focus(); 
    } 
}); 
+3

'返回false = event.stopPropagation()+ event.preventDefault()' – undefined

+0

对,没错,太多...... – Rab