如何通过 JS 将内容从一个表单中的一个文本框复制到另一个表单中的另一个文本框

how to copy contents from one textbox in one form to another textbox in another form through JS

本文关键字:表单 一个 文本 另一个 复制 何通过 JS      更新时间:2023-09-26
<form action="formoneaction" method="post">
  <input type="text" id="t1" />
  <button type="sumbit" class="btn">Insert</button>
</form>
<form action="formtwoaction" method="post">
  <input type="text" id="t2" />
  <button type="sumbit" class="btn">Insert</button>
</form>
<script>
    var t1 = document.getElementById('t1');
    t1.onkeyup = t1.onchange = function() {
      document.getElementById('t2').value = this.value;
    };
</script>

当两个元素采用不同的形式时,如何使脚本工作?当它们都不在表单中时,脚本会起作用。

以前从未学过JS,所以当有人解释一堆行话时,我可能不太理解。对不起,我会尽力的!

试试下面的代码,它将数据从textbox复制到TextArea

$("#textArea").append("'n * " + $("#textBox").val());

工作演示