Add tinymce to new textarea dynamically

≯℡__Kan透↙ 提交于 2019-11-27 06:58:51

问题


How can i do this

function addTinyText(id, text){
//add textarea to DOM
$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');
//init tineMCE
 tinyMCE.init({
        theme : "advanced",
        plugins : "emotions,spellchecker"
});
//add tinymce to this
tinyMCE.execCommand("mceAddControl", false, 'txt'+id);
}

but as a result every time we have a new textarea+tinyMCE but no text inside

What do i wrong?


回答1:


I searched a very long time to find an answer to a similar problem.

My content was not being posted even thou I could get the editor to appear.

I got it working like this:

    jQuery('.wysiwyg').tinymce({
      // Location of TinyMCE script
      script_url : 'path/tinymce/tiny_mce.js',

      // General options
      theme : "advanced",
     .........
     .........
     ......... etc

I used the standard jquery code to initiate all text areas with class name wysiwyg as tinymce objects.

After ajax call completes and new textarea is loaded I run this function:

jQuery(".wysiwyg").each(function(){ 
    tinyMCE.execCommand("mceAddControl",false, this.id);
});

Now my code is finally being posted correctly.




回答2:


line

$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');

should be line

$('<textarea id="txt'+id+'"></textarea>').text(text).appendTo('body');


来源:https://stackoverflow.com/questions/9091619/add-tinymce-to-new-textarea-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!