Appending a javascript variable to an html textarea
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4454664/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Appending a javascript variable to an html textarea
提问by Guyver
I know this has to be be doable, does anyone know how and if you can do it?
I know this has to be be doable, does anyone know how and if you can do it?
回答by u476945
or you can do it this way:
or you can do it this way:
var myVar = 'sup fresh our turn baby!';
var myTextArea = document.getElementById('myArea');
myTextArea.innerHTML += myVar;
回答by Greg
Something like this should work:
Something like this should work:
var textArea = document.getElementById("mytextarea"); // assuming there is a textarea with id = mytextarea
var textToAppend = document.createTextNode("Hello, World!");
textArea.appendChild(textToAppend);
EDIT:or, as Pointy suggested, the last two lines can be replaced by:
EDIT:or, as Pointy suggested, the last two lines can be replaced by:
textArea.value += "Hello, World!";
回答by Enrique
function appendText(str) {
var obj=document.getElementById("myTextArea")
var txt=document.createTextNode("append this text")
obj.appendChild(txt)
}
回答by Pointy
Gee whiz guys:
Gee whiz guys:
document.getElementById('whatever').value += someJavascriptString;

