html代码:
<input type="text" style='width:20px;' maxlength="2"/>
<input type="text" style='width:20px;' maxlength="2"/>
请问如果在第一个input中粘贴一个长度为4的数字后,立即自动触发一个函数事件,是长度为4的数字分别显示在两个input中
<input type="text" style='width:20px;' maxlength="2"/>
<input type="text" style='width:20px;' maxlength="2"/>
请问如果在第一个input中粘贴一个长度为4的数字后,立即自动触发一个函数事件,是长度为4的数字分别显示在两个input中
<html>
<head></head>
<script type="text/javascript">
function test(event)
{
//window.event.returnValue=false;
var str = clipboardData.getData("Text");
document.getElementById("text2").value = str.substr(2,2);
}
</script>
<body>
<input type="text" id="text1" style='width:20px;' maxlength="2" onbeforepaste="test();"/>
<input type="text" id="text2" style='width:20px;' maxlength="2"/>
</body>
</html>
function test()
{
//window.event.returnValue=false;
var t=document.getElementById("text1").value;
if(t.length>2){
document.getElementById("text2").value = t.substr(2,2);
document.getElementById("text1").value=t.substr(0,2);
}
}
</script>
<body>
<input type="text" id="text1" style='width:100px;' maxlength="4" onChange ="test();"/>
<input type="text" id="text2" style='width:100px;' maxlength="2"/>
</body>
<script type="text/javascript">
function test()
{
//window.event.returnValue=false;
var t=document.getElementById("text1").value;
if(t.length>2){
document.getElementById("text2").value = t.substr(1,2);
document.getElementById("text1").value=t.substr(0,1);
}
}
</script>
<body>
<input type="text" id="text1" style='width:100px;' maxlength="4" onKeyPress="test();"/>
<input type="text" id="text2" style='width:100px;' maxlength="2"/>
</body>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function setMyPaste(input) {
var value = input.value;
document.getElementById("receive1").value = value.substr(0,2);
document.getElementById("receive2").value = value.substr(2,2);
}
</script>
</head>
<body>
<table border="1">
<tr>
<td>粘贴输入框</td>
<td>
<input onpropertychange="setMyPaste(this)"/>
</td>
</tr>
<tr>
<td>接收输入框1</td>
<td>
<input id="receive1" />
</td>
</tr>
<tr>
<td>接收输入框2</td>
<td>
<input id="receive2"/>
</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function splitNum(){
var strNum=window.clipboardData.getData("Text");
var strNum2,len;
strNum2="";
len=strNum.length;
if(len>2){
strNum2=strNum.substring(2);
}
document.getElementById("numb2").value = strNum2;
}
</script>
</head><body>
<input type="text" style='width:20px;' maxlength="2" id="numb1" onpropertychange="splitNum();"/>
<input type="text" style='width:20px;' maxlength="2" id="numb2"/>
</body>
</html>