Set textarea value with javascript after TinyMCE initializing

前端 未结 6 666
终归单人心
终归单人心 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('<p>This is my new content!</p>');
    

    You may also acces the dom elements directly using the following

    tinymce.get('title').getBody().innerHTML = '<p>This is my new content!</p>';
    

    or using jQuery

    $(tinymce.get('title').getBody()).html('<p>This is my new content!</p>');
    
    0 讨论(0)
  • 2021-02-01 15:43

    It works for me. Just place it inside your html code instead of going tinymce

        <textarea> html CONTENT</textarea>
    
    0 讨论(0)
  • 2021-02-01 15:46

    Simply this works for me

    $("#description").val(content);
    
    0 讨论(0)
  • 2021-02-01 15:46
    <textarea id="content" name="content">{{html_entity_decode($yourstringdata)}}</textarea>
    

    This is work for me, Decode your html data and place it between start and closing textarea tags.

    0 讨论(0)
  • 2021-02-01 15:53

    I had the same problem solved by making sure the setContent was done after the document is ready, so first;

    script(type="text/javascript").
      tinymce.init({
        selector: '#title',
        height: 350,
        menubar: false
      });
    

    then

    script(type='text/javascript').
      $(document).ready(function(){
        tinymce.get('title').setContent('<span>someText</span> is html');
      })
    

    Above is code for pug, but the key is -as mentioned- to load it on document ready.

    0 讨论(0)
  • 2021-02-01 16:02

    You can use the tinyMCE.activeEditor.setContent('<span>some</span> html');

    Check this Answer

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