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

2024-03-29

我在初始化后动态地将tinymce添加到textarea时遇到了一个小问题。

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

我的按钮添加新的文本区域:

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

我尝试过这样做tinyMCE.execCommand('mceAddControl', false, '');但这没有用。


你试过打电话吗tinymce.init函数在appendTo函数之后?

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何动态添加tinymce 4.x到textarea? 的相关文章

随机推荐