如何动态添加 tinymce 4.x 到 textarea?
How to add tinymce 4.x dynamically to textarea?
我在初始化后动态添加 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, '');
但是没用。
您是否尝试过在 appendTo 函数之后调用 tinymce.init
函数?
jQuery 函数同步运行,一次一个。这意味着,您的 init 函数将在 appentTo
完成后 运行,这意味着您不需要回调。
只需在 appendTo
之后写下您的 tinymce.init
函数,然后返回这里告诉结果 :)
我在初始化后动态添加 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, '');
但是没用。
您是否尝试过在 appendTo 函数之后调用 tinymce.init
函数?
jQuery 函数同步运行,一次一个。这意味着,您的 init 函数将在 appentTo
完成后 运行,这意味着您不需要回调。
只需在 appendTo
之后写下您的 tinymce.init
函数,然后返回这里告诉结果 :)