想实现一个功能有两个输入框,在第一个输入框输入手机号码输入完后(一定是要输入完11位),第2个框自动获得焦点,请问该怎样实现

解决方案 »

  1.   

    <script   language="javascript">   
    function pd(){
    if(document.f1.txt1.value.length != 11){
    alert("不等于11位");
    document.f1.txt1.focus();
    }else{
    document.f1.txt2.focus();
    }
    }
      </script>
    <form name="f1">
    <input type="text" name="txt1" onBlur="pd()" />
    <input type="text" name="txt2" />
    </form>
      

  2.   


    <input type="text" id="txt1" onkeyup="chklength()" maxlength=11/>
    <input type="text" id="txt2" />
    <script language="javascript">
    function chklength(){
       if (txt1.value.length==11) {txt2.focus(); txt2.select();}

    </script>
      

  3.   

    if (txt1.value.length==11) {txt2.focus(); txt2.select();}
      

  4.   


    <input type="text" id="txt1" onkeyup="AutoNext(this.value)" maxlength=11/>
    <input type="text" id="txt2" />
    <script language="javascript">
    function AutoNext(s){
       if (s.length==11) {txt2.focus(); txt2.select();}

    </script>
      

  5.   

    <html> 
    <head> 
    <title>自动获取焦点</title> 
    </head> 
    <body> <input name="key" type="text" id="key"  onFocus="clearq()">
    <input name="2N" type="text" id="asdda" OnKeyPress="getID()">
    <script>
    function getID(){
    var valueID=document.getElementById("asdda").value;
    if(valueID.length>=11){
    document.getElementById("key").focus();
    }
    }
    function clearq(){
    document.getElementById("key").value="";
    }
    </script></body> 
    </html> 
    参考一下,基本能实现!
      

  6.   

     C#代码:
    void Form1_textBox1_TextChanged(object sender, System.EventArgs e)
     {
        if (textBox1.Text.Length == 11)
        {
           textBox2.Focus();
        }
     }