0

嗯,这就是我的意思。假设我有 2 个文本区域:

<textarea id="first" class="txtarea" name="in_first" cols="80" rows="15">First Textarea</textarea>

和:

<textarea id="second" class="txtarea" name="in_second" cols="80" rows="15">First Textarea</textarea>

在最终结果中,我只想用 javascript 将第一个 textarea 的值移动到第二个 textarea,请不要向我推荐任何其他编程语言。

我已经使用如下代码获得了第一个 textarea 的值:

var textAreaValue = $("#first").text();

现在,我怎样才能将它插入到第二个文本区域?或者你有其他方法,请告诉我。

4

6 回答 6

6

使用 jquery val() 方法:

$firsttextarea=$("#first").val();
$('#second').val($firsttextarea);

使用 jquery text() 方法:

$firsttextarea=$("#first").text();
$('#second').text($firsttextarea);
于 2013-05-20T09:58:38.737 回答
2

然后,仅使用 JS(无库):

var firstTextArea = document.getElementById('first');
document.getElementById('second').value = first.value;

//clearing the first
first.value = '';
于 2013-05-20T09:55:02.723 回答
0

在纯 JavaScript 中,它应该如下所示:

var value = document.getElementById("first").value;
document.getElementById("second").value = value;

请注意,对于表单元素(如<textarea>),您应该处理value属性。

如果要清除第一个的值,<textarea>请执行以下操作:

document.getElementById("first").value = "";
于 2013-05-20T09:55:00.737 回答
0

你可以使用 jQuery:

var textAreaValue = $("#first").text();
$("#second").text(textAreaValue);

清除 textArea 你可以使用:

$("#first").text("");
于 2013-05-20T09:57:39.913 回答
0

使用 jQuery

$('.second').val($('.first').val());

这仅供您参考。

于 2013-05-20T09:57:46.063 回答
0

html

<textarea id="first" class="txtarea" name="in_first" cols="80" rows="15">First Textarea</textarea>

<textarea id="second" class="txtarea" name="in_second" cols="80" rows="15">First Textarea</textarea>

jQuery

var FristTextAreaValue = $("#first").val();
var SecondTextAreaValue = $("#second").val();
于 2013-05-20T09:59:41.090 回答