【问题标题】:how to copy contents from one textbox in one form to another textbox in another form through JS如何通过JS将内容从一种形式的一个文本框复制到另一种形式的另一个文本框中
【发布时间】:2015-03-26 09:51:01
【问题描述】:
<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,所以当有人解释一堆行话时,我可能不太明白。对不起,我会努力的!

【问题讨论】:

  • 您的代码运行良好..您还需要什么
  • 什么意思,另一种形式
  • 由于某种原因,此脚本不适用于 textarea

标签: javascript html forms text copy


【解决方案1】:

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

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

Working Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多