62,025
社区成员
发帖
与我相关
我的任务
分享
<body>
<table >
<tbody>
<tr>
<td><input type=text /></td>
<td><input type=text /></td>
</tr>
<tr>
<td><input type=text /></td>
<td><input type=text /></td>
</tr>
<tr>
<td><input type=text /></td>
<td><input type=text /></td>
</tr>
<tr>
<td><input type=text /></td>
<td><input type=text /></td>
</tr>
</tbody>
</table>
</body>
<script type="text/javascript" src="JS/jquery-1.4.4.js"></script>
<script type="text/javascript">
$(function() {
$("input").eq(0).focus();
$("input[type='text']").keydown(function() {
var key = event.keyCode;
switch (key) {
case 37: //left
{
if ($(this).parent().prev().length >= 1) {
$(this).parent().prev().find("input").focus();
}
break;
}
case 38: //up
{
if ($(this).parent().parent().prev().length >= 1) {
$(this).parent().parent().prev().find("input").eq($(this).parent().prev().length).focus();
}
break;
}
case 39: //right
{
if ($(this).parent().next().length >= 1) {
$(this).parent().next().find("input").focus();
}
break;
}
case 40: //down
{
if ($(this).parent().parent().next().length >= 1) {
$(this).parent().parent().next().find("input").eq($(this).parent().next().length-1).focus();
}
break;
}
default:
{
break;
}
}
});
});
</script>