gpt4 book ai didi

javascript - 如何使用javascript将一个字段输入值复制到另一字段输入

转载 作者:行者123 更新时间:2023-11-28 17:41:01 24 4
gpt4 key购买 nike

想要在有人单击复选框时将某些字段从我的表单复制到另一个字段,并在取消选中复选框时将其删除。

我是怎么做到的,但它不起作用。

<script>
function filladdress(f) {
if(f.sameaddress.checked == true) {
f.present_address1.value = f.perm_address1.value;
f.present_address2.value = f.perm_address2.value;
f.present_address3.value = f.perm_address3.value;
}
}
</script>

这是表格..

<form name="OnlineForm" method="post" onsubmit="return OnSubmitForm();" action="apply4.php">
<input name="present_address1" type="text" title="Maximum 35 Character allowed" class="textBoxDashed" id="present_address1" value="" size="43" maxlength="35">
<input name="present_address2" type="text" title="Maximum 35 Character allowed" class="textBoxDashed" id="present_address2" value="" size="43" maxlength="35">
<input name="present_address3" title="Maximum 35 Character allowed" class="textBoxDashed" id="present_address3" value="" size="43" maxlength="35">

<input type="checkbox" name="sameaddress" onclick="filladdress(this.OnlineForm)">

<input name="perm_address1" type="text" title="Maximum 35 Character allowed" class="textBoxDashed" id="perm_address1" value="" size="43" maxlength="35">
<input name="perm_address2" type="text" title="Maximum 35 Character allowed" class="textBoxDashed" id="perm_address2" value="" size="43" maxlength="35">
<input name="perm_address3" type="text" title="Maximum 35 Character allowed" class="textBoxDashed" id="perm_address3" value="" size="43" maxlength="35">

最佳答案

当复选框单击时,在 html 中使用 document 代替 this

您将通过 this.OnlineForm 获得未定义的传递

请参阅此处演示 https://jsbin.com/subebaz/edit?html,js,output

并在复制功能中切换赋值顺序

关于javascript - 如何使用javascript将一个字段输入值复制到另一字段输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47950310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com