setContent of an textarea with tinyMCE

后端 未结 8 1757
无人及你
无人及你 2020-12-25 14:33

I have some textareas and all of them are with tinyMCE.

I would like to set the content of the specific textarea, but I can\'t find how.

I have tryed this:

相关标签:
8条回答
  • 2020-12-25 15:28

    In TinyMCE 5, you can do this using the setContent() method.

    Let’s say you have initialized the editor on a textarea with id=”myTextarea”. First access the editor using that same id, then call setContent(). For example:

    tinymce.get('#myTextarea').setContent('<p>Hello world!</p>');
    

    Or, instead of accessing the editor by id, you can access the active editor:

    tinymce.activeEditor.setContent('<p>Hello world!</p>');
    

    More info and examples here: https://www.tiny.cloud/blog/how-to-get-content-and-set-content-in-tinymce.

    0 讨论(0)
  • 2020-12-25 15:30

    I think this will solve your problem

    it works fine for TinyMCE v:4..

    // Sets the HTML contents of the activeEditor editor
    tinyMCE.activeEditor.setContent('<span>some</span> html');
    
    // Sets the raw contents of the activeEditor editor
    tinyMCE.activeEditor.setContent('<span>some</span> html', {format : 'raw'});
    
    // Sets the content of a specific editor (my_editor in this example)
    tinyMCE.get('my_editor').setContent(data); // here my_editor is the id of a specific editor
    
    // Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added
    tinyMCE.activeEditor.setContent('[b]some[/b] html', {format : 'bbcode'});
    

    the link for the code is TinyMCE setContent

    0 讨论(0)
提交回复
热议问题