简体   繁体   English

使用javascript将文本添加到文本区域

[英]Add text to text area using javascript

如何使用javascript在textarea中为已写入的文本添加自定义文本?谢谢...

function addText(elId,text) {
    document.getElementById(elId).value += text;
}

or: 要么:

function addText(elId,text) {
    var obj = document.getElementById(elId);
    var txt = document.createTextNode(text);
    obj.appendChild(txt);
}
myTextarea.value += "text to add to the textarea"

Grab the existing text in the textarea (the element's .value) 抓取textarea中的现有文本(元素的.value)

Combine your existing text (append, prepend, insert, or whatever you need) 合并现有文本(追加,前置,插入或任何你需要的)

Write the result back to the textarea. 将结果写回textarea。

Tah-dah! TAH-DAH!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM