javascript - 如何在 ajax 加载 textarea 后重新初始化 TinyMCE
问题描述
我正在尝试将 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
}
});
});
带有类的 divcomments-body
有几种带有 textareas 的表单,并在成功后重新加载。但是在重新加载后,tinymce 不再绑定!
我知道我必须使用tinyMCE.remove();
并且tinyMCE.init();
我在我的 ajax 中尝试过beforeSend
,complete
但没有结果。有人知道我在做什么错吗?我正在使用 tinymce 5 的免费 API
解决方案
推荐阅读
- python - 分类数据计数
- javascript - 尝试在 Angular 的新选项卡中打开网站但无法正常工作
- sql - 如何删除数据库中5分钟内取消的订单记录?
- javascript - 使用反应链接时如何防止外部网址附加到本地主机网址?
- javascript - 如何制作不和谐的嵌入链接
- c++ - 从字符串中提取字符时,基于范围的循环和字符串流有什么区别
- forms - 如何将表单数据发送到 API - Windev 24
- angular - 角度图像裁剪
- amazon-web-services - 在 dynamodb 单表中处理更多的多对多关系
- python - 如果我的 csv 文件存在于 S3,如何使用 nx.read_edgelist 创建图形?