How to add tinymce 4.x dynamically to textarea?

旧城冷巷雨未停 提交于 2019-12-10 15:33:19

问题


I have a little problem with adding tinymce dynamically to textarea after init.

tinymce.init({
    selector: "textarea",
    theme: "modern",
    height: 100,
    plugins: [
         "advlist autolink image lists charmap print preview hr anchor pagebreak spellchecker",
         "link searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   ],
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
 }); 

And my button to add new textarea:

$('#add_new_text').click(function(){
var n = 1;
$( '<textarea class="cla" name="text'+n+'"></textarea>' ).appendTo( '#wrap_f' );
n++;
   })

I've tried to do this tinyMCE.execCommand('mceAddControl', false, ''); But it didn't work.


回答1:


Have you tried calling tinymce.init function after the appendTo function?

jQuery functions operates synchronously, one at a time. That means, your init function will run after the appentTo completes, and that means, you don't need a callback for that.

Just write your tinymce.init funtion after the appendTo and get back here to tell the result :)



来源:https://stackoverflow.com/questions/30107547/how-to-add-tinymce-4-x-dynamically-to-textarea

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