本文介绍了将值从一个输入字段复制到另一个输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个javascript函数来根据复选框选择将一个输入字段的值复制到另一个输入字段。然而,我点击了一些javascript代码,
< script>
函数copyTextValue(){
var text1 = document.getElementById(Name1)。value;
document.getElementById(Name2)。value = text1;
document.getElementById(Name3)。value = text1;
}
< / script>
< input type =checkboxname =check1onclick =copyTextValue();/>
现在我需要删除这两个框中的复制值。我坚持这一点。任何帮助?
解决方案
function copyTextValue (bf){var text1 = bf.checked? document.getElementById(Name1)。value:''; document.getElementById(Name2)。value = text1; document.getElementById(Name3)。value = text1;}
< input type =checkboxname =check1onchange =copyTextValue(this); />< input id =Name1>< input id =Name2>< input id =Name3>
I need a javascript function for copying the value of one input field to another input field based on checkbox selection. However i did some javascript code on click,
<script>
function copyTextValue() {
var text1 = document.getElementById("Name1").value;
document.getElementById("Name2").value = text1;
document.getElementById("Name3").value=text1;
}
</script>
<input type="checkbox" name="check1" onclick="copyTextValue();"/>
Now i need to delete the copied values in those two boxes on uncheck. I stuck up with this. Any help?
解决方案
function copyTextValue(bf) {
var text1 = bf.checked ? document.getElementById("Name1").value : '';
document.getElementById("Name2").value = text1;
document.getElementById("Name3").value = text1;
}
<input type="checkbox" name="check1" onchange="copyTextValue(this);" />
<input id="Name1"><input id="Name2"><input id="Name3">
这篇关于将值从一个输入字段复制到另一个输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!