使用单个文本框在其他框中输入值 [英] using single text box to enter value in other box
问题描述
嗨frnds,
我试图创建文本框,用于逐个输入其他4个文本框中的值
i尝试了下面的代码,但它只复制到一个文本框...
< html>
< head>
< script>
function copy_data(val){
var a = document.getElementById(val.id).value
document.getElementById(copy_to)。value = a
}
< / script>
< / head>
<正文>
< input type =textname =aid =copy_fromonKeyUp =copy_data(this)/>
< input type =textname =aid =copy_todisabled />
< ; input type =textname =aid =copy_todisabled />
< input type =textname = aid =copy_to已停用/>
& lt; input type =textname =aid =copy_todisabled />
< input type =textname =aid =copy_to已停用/>
< / body>
< / html>
hi frnds,
im trying to create text box which is used to enter value in other 4 text box one by one
i had tryed the below code but it copy's only to one text box...
<html>
<head>
<script>
function copy_data(val){
var a = document.getElementById(val.id).value
document.getElementById("copy_to").value=a
}
</script>
</head>
<body>
<input type="text" name ="a" id="copy_from" onKeyUp="copy_data(this)"/>
<input type="text" name ="a" id="copy_to" disabled/>
<input type="text" name ="a" id="copy_to" disabled/>
<input type="text" name ="a" id="copy_to" disabled/>
<input type="text" name ="a" id="copy_to" disabled/>
<input type="text" name ="a" id="copy_to" disabled/>
</body>
</html>
推荐答案
嗨看看修改后的代码
hi have a look of the modified code
<script>
function copy_data(val){
var a = document.getElementById(val.id).value
var elemArray = document.getElementsByName("a");
for(var i = 0; i < elemArray.length; i++){
var elem = document.getElementById(elemArray[i].id);
elem.value=a;
}
}
</script>
请查看完整代码
http:// www.dotnetpools.com/2013/11/documentgetelementsbyname-using.html [ ^ ]
这篇关于使用单个文本框在其他框中输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!