input输入框点击回车切换到下一个输入框功能

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
$(function() {
  $('#txtLoginAccount').focus();//自动聚焦在输入账号的输入框
  $('#txtLoginAccount').keydown(function(e) {
    if (e.which == 13) {
	  if ($(this).val() != "") {
	    $("#txtLoginPassword").focus();//回车键后,聚焦在输入密码的输入框
	  }
	}
  });
  $('#txtLoginPassword').keydown(function(e) {
    if (e.which == 13) {
	  if ($(this).val() != "") {
	    login();//登录方法
	  }
	}
  });
}); 
</script>
<body>
  <div id="content">
   <form id="form_login" action="login.do" method="post">
     <input type="text" name="userName" id="txtLoginAccount" value="" /> 
     <input type="password" name="password" id="txtLoginPassword" value="" />
   </form>
  </div> 
</body>
</html>

版权声明:本文为qq_44473460原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。