如何动态添加tinymce 4.x到textarea?

我在初始化后向textarea动态添加tinymce时遇到了一些问题。

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'} ] }); 

我的按钮添加新的textarea:

 $('#add_new_text').click(function(){ var n = 1; $( '' ).appendTo( '#wrap_f' ); n++; }) 

我试过这个tinyMCE.execCommand('mceAddControl', false, ''); 但它没有用。

您是否尝试过appendTo函数后调用tinymce.init函数?

jQuery函数同步运行,一次一个。 这意味着,你的init函数将在appentTo完成后运行,这意味着你不需要回调。

只需在appendTo之后写下你的tinymce.init函数,然后回到这里告诉结果:)