用户粘贴过来的形式是 (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" />
帮忙看看是哪里的问题呢?
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" />
帮忙看看是哪里的问题呢?
解决方案 »
- 求教一个web开发方面的一个基本业务逻辑
- JS 元素交换了位置,其绑定事件丢失了,怎么处理?
- 关于nextSibling,大家帮帮忙
- 怎样得到文本节点的值?var a=document.createTextNode("ssss") 中的ssss
- 关于对JavaScript的学习
- 怎么让网页上的链接都不可点?
- 请高手介绍一下有关无刷新技术的实现方法和原理,最好有例子,不胜感激!!
- 问个关于checkbox里onchange的问题
- ■■高分请教:能够实现在ListBox中的列表项旁边加一个checkBox吗?我这样做不行啊,请看:■■
- Uncaught TypeError: Cannot read property 'path' of undefined
- 如何用javascript控制元素属性
- 在线等
改成:
<input type="text" name="po1" id="postcode" onpaste="popaste();return false;" />
即可
<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>