用户粘贴过来的形式是 (A=字母,N=数字,后面是例子):
AN NAA         M2 5BQ 
ANN NAA        M34 4AB 
AAN NAA        CR0 2YR 
AANN NAA       DN16 9AA 
ANA NAA        W1A 4ZZ 
AANA NAA       EC1A 1HQ我用js将粘贴得字符串按空格分成两段,分配到两个input框,但是现在的情况是,第一框分配的是整个字符串,第二个框则没问题。function $$(id){return document.getElementById(id);}
String.prototype.trim   =   function()  {  return   this.replace(/(^\s*)|(\s*$)/g, ""); }   
function popaste(){var c=window.clipboardData.getData('text'); c=c.trim();
    carray=c.split(" ");
    $$("postcode").value=carray[0];
    if (carray[1]!=null){$$("postcode2").value=carray[1]; $$("postcode2").focus();}
    }
 
<input type="text" name="po1" id="postcode" onpaste="popaste();" /> <input type="text" name="po2" id="postcode2" />
帮忙看看是哪里的问题呢?

解决方案 »

  1.   

    我来理你了<input type="text" name="po1" id="postcode" onpaste="popaste();" />
    改成:
    <input type="text" name="po1" id="postcode" onpaste="popaste();return false;" />
    即可
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>New Document </title>
    <script language="JavaScript" type="text/javascript">
    function $$(id){return document.getElementById(id);}
    String.prototype.trim   =   function()  {  return   this.replace(/(^\s*)|(\s*$)/g, ""); }   
    function popaste(){var c=window.clipboardData.getData('text'); c=c.trim();
        carray=c.split(" ");
        $$("postcode").value=carray[0];
        if (carray[1]!=null){$$("postcode2").value=carray[1]; $$("postcode2").focus();}
        } 
    </script>
     </head>
     <body> <form action="somepage.asp" name=theForm">
      <input type="text" name="po1" id="postcode" onpaste="popaste();return false;"  /> <input type="text" name="po2" id="postcode2" />
     </form>
     </body>
     </html>