我正在尝试将tinyMCE重新绑定到使用Ajax动态生成的textarea。 我的tinymce看起来像这样:
tinyMCE.init({
selector : "textarea",
plugins: "emoticons link",
menubar: false,
toolbar: 'undo redo | bold italic underline | fontsizeselect | link | emoticons',
height: 240,
force_br_newlines : true,
force_p_newlines : false,
forced_root_block : '',
paste_as_text: true,
});
我的ajax发送数据:
$('body').on('submit', '.comment_form', function (e) {
e.preventDefault();
tinyMCE.triggerSave(); // save TinyMCE instances before sending data
....
$.ajax({
url: 'comment.php',
type: 'POST',
data: {
comment_name:comment_name,
comment:comment,
},
beforeSend: function(){
tinyMCE.remove(); // remove tiny mce form textarea
},
success: function(data){
$('.result').html(data);
$('.modal').modal('hide'); // close modal
$(".comments-body").load(" .comments-body > *"); // reload div comments-body from comments
},
complete:function(){
tinyMCE.init(); // rebind tinymce to textarea
}
});
});
类comments-body
的div具有几种形式的textareas,成功后将重新加载。
但是在重新加载后,tinymce不再绑定了!
我知道我必须使用tinyMCE.remove();
和tinyMCE.init();
,并且在ajax beforeSend
和complete
中尝试了该方法,但没有结果。
有人知道我在做什么错吗?
我正在使用tinymce 5的免费API