键入后如何更改textarea的innerHTML? [英] how to change innerHTML of textarea after typing in it?
本文介绍了键入后如何更改textarea的innerHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我不首先在textarea框中键入以下代码,则仅 有效.如果我键入它,则单击div不会执行任何操作.有什么办法可以在javascript中解决此问题?感谢您的帮助.
The following code works only if I don't first type in the textarea box. If i type in it, clicking on the div does nothing. Is there any way to fix this in javascript or whatever? Any help is appreciated.
<textarea id = "textarea">change this</textarea>
<div onclick = "change()">click here<div>
<script>
function change()
{
document.getElementById( 'textarea' ).innerHTML = 'new text';
}
</script>
这是jsfiddle http://jsfiddle.net/69n24agz/
here is the jsfiddle http://jsfiddle.net/69n24agz/
推荐答案
将innerHTML更改为值
Change innerHTML to value,
<textarea id = "textarea">change this</textarea>
<div onclick = "change()">click here<div>
<script>
function change()
{
document.getElementById( 'textarea' ).value = 'new text';
}
</script>
一个textarea的值可以更改,这里的innerHTML只是设置初始值.
a textarea has a value that can be altered, the innerHTML here just sets the initial value.
这篇关于键入后如何更改textarea的innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文