![](/img/trans.png)
[英]How to get a textarea's value and put it into another textarea using Javascript?
[英]how to insert value of an textarea to another textarea with javascript
好吧,這就是我的意思。 可以說我有2個textarea:
<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,請不要對我使用任何其他編程語言。
我已經使用以下代碼獲取了第一個文本區域的值:
var textAreaValue = $("#first").text();
現在,如何將其插入第二個文本區域? 也許您還有其他方法,請告訴我。
使用jquery val()方法:
$firsttextarea=$("#first").val();
$('#second').val($firsttextarea);
使用jQuery text()方法:
$firsttextarea=$("#first").text();
$('#second').text($firsttextarea);
然后,僅使用JS(無庫):
var firstTextArea = document.getElementById('first');
document.getElementById('second').value = first.value;
//clearing the first
first.value = '';
在純JavaScript中,它應類似於:
var value = document.getElementById("first").value;
document.getElementById("second").value = value;
請注意,對於表單元素(例如<textarea>
),您應該處理value
屬性。
如果要清除第一個<textarea>
的值,請執行以下操作:
document.getElementById("first").value = "";
您可以使用jQuery:
var textAreaValue = $("#first").text();
$("#second").text(textAreaValue);
清除textArea您可以使用:
$("#first").text("");
使用jQuery
$('.second').val($('.first').val());
僅供參考。
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.