日期:2014-05-18  浏览次数:20449 次

关于如何让两个text跳转
在页面上有两个textbox。第一个的maxlength是4,当我输入四个字符后我希望可以自动跳转到第二个textbox。请问怎么实现呢。谢谢

------解决方案--------------------
用javascript:

<script>
function TranFocus(obj,nextelementid)
{
if(obj.value.length > = obj.maxLength)
{
document.getElementById(nextelementid).focus();
}
return true;
}
</script>

然后表单里面:
<form action= " " name= "form1 " id= "form1 " method= "post ">
<input name= "textfield " type= "text " id= "textfield " maxlength= "4 " onkeypress= "TranFocus(this, 'textfield2 '); " />
<input name= "textfield2 " type= "text " id= "textfield2 " maxlength= "4 " />
</form>