Set textarea value with javascript after TinyMCE initializing

前端 未结 6 680
终归单人心
终归单人心 2021-02-01 14:59

I hava an textarea and I am using tinyMCE on that textarea.

What I am doing actually is that when the page is opened, I am populating the textarea with some text, and af

6条回答
  •  情深已故
    2021-02-01 15:38

    Problem here is you won't see anything if you enter text or html into your textarea. Your textarea gets hidden when tinymce gets initialized. What you see then is a content editable iframe, which is used to edit and style content. There are several events which will cause tinymce to write its content to the html source element of the editor (in your case your textarea).

    If you want to set the content of the editor (which is visible) you will need to call something like

    tinymce.get('title').setContent('

    This is my new content!

    ');

    You may also acces the dom elements directly using the following

    tinymce.get('title').getBody().innerHTML = '

    This is my new content!

    ';

    or using jQuery

    $(tinymce.get('title').getBody()).html('

    This is my new content!

    ');

提交回复
热议问题