简体   繁体   中英

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)

Combine your existing text (append, prepend, insert, or whatever you need)

Write the result back to the textarea.

Tah-dah!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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