<SCRIPT language="javascript"> <!-- function document.onkeydown() { switch(event.keyCode) { case 13: case 39: case 40: GoOtherText(1); break; case 37: case 38:GoOtherText(-1);break; default: break; }
}
function GoOtherText(iDirection) { var i= event.srcElement.sourceIndex; var obj = document.all[i+iDirection];while(i>=0 && obj.tagName.toUpperCase() !="INPUT") { obj = document.all[i+iDirection]; i+= iDirection; if(i==-1||i>=document.all.length) return; } window.status = i;
<!--
function document.onkeydown()
{
switch(event.keyCode)
{
case 13:
case 39:
case 40:
GoOtherText(1);
break;
case 37:
case 38:GoOtherText(-1);break;
default:
break;
}
}
function GoOtherText(iDirection)
{
var i= event.srcElement.sourceIndex;
var obj = document.all[i+iDirection];while(i>=0 && obj.tagName.toUpperCase() !="INPUT")
{
obj = document.all[i+iDirection];
i+= iDirection;
if(i==-1||i>=document.all.length) return;
}
window.status = i;
if(obj.tagName.toUpperCase() == "INPUT" && obj.type== "text")
{
obj.focus();
obj.select();
}
}
//-->
</SCRIPT>
<input type=text id=text1 onkeyup=ustbwuyi() />
<input type=text id=text2 />
<script language=javascript> function ustbwuyi
{
if(event.keyCode==13)
{
document.getElementById("text2").focus();
}
}</script>
然后在文本框的onkeyup事件里面判断是否目前输入的长度达到了你的规定,达到的话就转移
给你一个简单例子,你可以扩展一下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function test(e)
{
if(e.value.length == e.maxLength)
{
var tx2 = document.getElementById("tx2");
tx2.focus();
}
}
</script>
</head><body>
<input type="text" maxlength="5" id="tx1" width="50px" onkeyup="test(this);" />
<input type="text" maxlength="5" id="tx2" width="50px" />
</body>
</html>