最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to change innerHTML of textarea after typing in it? - Stack Overflow

programmeradmin1浏览0评论

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>

here is the jsfiddle /

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>

here is the jsfiddle http://jsfiddle/69n24agz/

Share Improve this question asked Dec 28, 2014 at 6:44 user4330208user4330208
Add a ment  | 

1 Answer 1

Reset to default 6

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>

a textarea has a value that can be altered, the innerHTML here just sets the initial value.

发布评论

评论列表(0)

  1. 暂无评论