js无法自动移动到下一个字段(表单框)??

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">  <script type="text/javascript">
        function moveNext(obj,index)
    {
    if(obj.value.length==4)
    {
    document.forms[0].elements[index+1].focus();
    }
    }
      
      function getResult()
      {
     var f=document.forms[0];
     var result="";
     for(var i=0;i<4;i++)
     {
        result+=document.forms[0].elements[i].value;
     }
      alert(result);
      }
      </script>
     </head> <body onload="document.forms[0].elements[0].focus()" >
      <form>
     <input type="text" id="a" size="3" onkeyup="moveNext(this,0)">-
     <input type="text" id="b"  size="3" onkeyup="moveNext(this,1)">-
     <input type="text" id="c" size="3" onkeyup="moveNext(this,2)">-
         <input type="text" id="d" size="3" onkeyup="moveNext(this,3)"><br>
     <input type="button" value="click" onkeyup="getResult()">  
      </form>
     </body>
    </html>
      

  2.   

    lz,我测试了下firefox、IE、遨游都没问题啊....不过input 最好再加个maxlength="4"。