补充一下,每个输入框的maxlength=2

解决方案 »

  1.   

    我实现的效果,学习~
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
        function chaifen()
        {
            var val = document.getElementsByName("num1")[0].value;
            var array = val.split("-");
            if(array != "")
            {
               document.getElementsByName("num1")[0].value = array[0];
               document.getElementsByName("num2")[0].value = array[1];
               document.getElementsByName("num3")[0].value = array[2];
               document.getElementsByName("num4")[0].value = array[3];
               document.getElementsByName("num5")[0].value = array[4];
               
            }
            //01-02-03-04-05
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input type=text name=num1 onkeyup="chaifen()" onfocus="this.select()">
    <input type=text name=num2 maxlength="2">
    <input type=text name=num3 maxlength="2">
    <input type=text name=num4 maxlength="2">
    <input type=text name=num5 maxlength="2">    </div>
        </form>
    </body>
    </html>
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml"  > 
    <head> 
         <title >Untitled Page </title > 
         <script type="text/javascript" > 
        function chaifen() 
        { 
            var val = document.getElementsByName("num1")[0].value; 
            var array = val.split("-"); 
            if(array != "") 
            { 
               document.getElementsByName("num1")[0].value = array[0]; 
               document.getElementsByName("num2")[0].value = array[1]; 
               document.getElementsByName("num3")[0].value = array[2]; 
               document.getElementsByName("num4")[0].value = array[3]; 
               document.getElementsByName("num5")[0].value = array[4]; 
                
            } 
            //01-02-03-04-05 
        } 
         </script > 
    </head > 
    <body > 
         <form id="form1"> 
         <div > 
         <input type=text name=num1 onkeyup="chaifen()" onfocus="this.select()" > 
    <input type=text name=num2 maxlength="2" > 
    <input type=text name=num3 maxlength="2" > 
    <input type=text name=num4 maxlength="2" > 
    <input type=text name=num5 maxlength="2" >      </div > 
         </form > 
    </body > 
    </html >
      

  3.   

     <html xmlns="http://www.w3.org/1999/xhtml"   > 
    <head > 
          <title  >Untitled Page  </title  > 
          <script type="text/javascript"  > 
        function chaifen() 
        { 
            var val = window.clipboardData.getData("text"); 
            var array = val.split("-"); 
            if(array != "") 
            { 
               document.getElementById("num1").value = (array[0])?array[0]:""; 
               document.getElementById("num2").value = (array[1])?array[1]:""; 
               document.getElementById("num3").value = (array[2])?array[2]:""; 
               document.getElementById("num4").value = (array[3])?array[3]:""; 
               document.getElementById("num5").value = (array[4])?array[4]:""; 
                
            } 
            //01-02-03-04-05 
        } 
          </script  > 
    </head  > 
    <body  > 
          <form id="form1" > 
          <div  > 
          <input type=text name=num1 > 
    <input type=text name=num2 maxlength="2"> 
    <input type=text name=num3 maxlength="2"> 
    <input type=text name=num4 maxlength="2"> 
    <input type=text name=num5 maxlength="2"> 
    <input type=button name=button1 value="自动填写" onclick="chaifen()"> 
          </div> 
          </form> 
    </body> 
    </html>