<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'left.jsp' starting page</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-1.5.2.js"></script>
<script type="text/javascript">
//$(function(){
// $("#name").focus();
//});
//$(function(){
/*function load(){
var input=document.getElementsByTagName("input");
//alert(input.length);
var event = window.event || arguments[0];
for(var i=0;i<input.length;i++){
document.getElementById("textf"+i).onkeydown=function (){
//alert("333");
//alert("555");
// if(event.keyCode == 13){
// var textid=i+1;
// event.keyCode=9;
var index=i;
alert(index);
$("input:text:eq("+index+")").focus();
//}
//$("#textf"+(i+1)).focus();
//event.keyCode = (event.keyCode == 13)?9:event.keyCode;
}
}
}*/
$(function(){
$("input:eq(0)").focus();
var $input = $("input");
$input.bind("keydown",function(e){
var key = e.which;
if(key==13){
e.preventDefault();
var index= $input.index(this)+1;
if(index==4){
$("#subForm").submit();
index=0;
//$("input:eq("+index+")").css("border-color","blue");
}
alert(index);
console.log(index);
$("input:eq("+index+")").focus();
//$("input:eq("+index+")").css("border-color","blue");
//$("input:eq("+index+")").parent().parent().siblings().find("input").css("border-color","#ccc");
}
});
});
//});
//var document.getElementsByTagName("input");
//function getName(){
// event.keyCode = (event.keyCode == 13)?9:event.keyCode;
//}
//function getName(){
// $("#age").focus();
//}
//function getAge(){
// $("#hobby").focus();
//}
//function getHobby(){
// $("#sub").focus();
//}
</script>
<style type="text/css">
input:focus{
border:1px solid red;
}
</style>
</head>
<body>
<form action="www.baidu.com" id="subForm" method="post">
<table>
<tr>
<td>姓名</td>
<td><input type="text" id="textf0" /></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" id="textf1" /></td>
</tr>
<tr>
<td>爱好</td>
<td><input type="text" id="textf2" /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="textf3" onclick="return document.forms[0].submit();" value="确定"/></td>
</tr>
</table>
</form>
</body>
</html>