【问题标题】:load page with tinymce (AJAX)使用 tinymce (AJAX) 加载页面
【发布时间】:2012-06-04 14:40:47
【问题描述】:

我在使用 jQuery 加载页面时没有问题,但是当我使用 textarea 加载页面时,应该不会显示 tinymce。

$.ajax({
type: "POST",
url: 'textarea.php',
data: {data: info},
async: false,
beforeSend: function() {
},
complete: function() {
},        
cache: false,
success:  function(result) {
  $('#form-area').html(result);
}
error: function(error) {
alert("Some problems have occured. Please try again later: " + error);
}

});

【问题讨论】:

  • 我们可以获取您的一些代码吗?到目前为止你尝试了什么?

标签: ajax tinymce wysiwyg


【解决方案1】:

看起来您应该在将来自 ajax 请求的 html 代码插入到 dom 之后立即调用 tinymce.init 函数。您也可以致电

tinymce.execCommand('mceAddControl',true,'editor_id');

您需要记住,您应该关闭 tinymce 编辑器实例,以防您想使用 ajax 重新加载编辑器实例。在这种情况下使用

tinymce.execCommand('mceRemoveControl',true,'editor_id');

【讨论】:

  • mode : "textareas", theme : "advanced", editor_selector : "mceEditor", editor_deselector : "mceNoEditor", //editor_id可以改成class_name吗??
  • 编辑器将获取底层 html 元素的 id(通常是 textarea),您可以相应地更改该 id
【解决方案2】:

当您使用 ajax 切换页面时,TinyMCE 似乎会中断。为了解决这个问题,我添加了以下代码以在再次初始化之前删除所有现有的 TinyMCE 实例

  if(window.tinymce){
    $(window.tinymce.editors).each(function(idx, p) {
    window.tinymce.remove(idx);
    });
  }

  tinyMCE.init({
        selector: "#risksummary",
        menubar: false,
        plugins : "table",
        toolbar: "table"
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    相关资源
    最近更新 更多