【问题标题】:set content in dynamically loaded tinyMCE editor在动态加载的 tinyMCE 编辑器中设置内容
【发布时间】:2012-07-02 07:46:26
【问题描述】:

我有网页 (index.pl),在它的 div (id = 'right') 中,我动态加载了一个包含 textarea 的页面 (editor.pl)。要将此文本区域更改为 TinyMce 编辑器,我已经动态加载了一个具有 tinyMce.init() 函数的 js 文件 (include_tiny_mce.js),如下所示:

$.ajax({
    type:'POST',
    url:'editor.pl',
    success:function(msg){
    $("#right").html(msg);
    $("head").append("<script src='/include_tiny_mce.js'></script><script src='/scripts.js'></script>");

    },

现在这一切工作正常,所有文本区域都更改为 tinyMce,但是当我使用 js 文件(script.js,已包含在 index.pl)中的
tinyMCE.activeEditor.setContent("hello world");
来设置内容时tinyMce 它没有显示内容。 谁能告诉我解决方法?

【问题讨论】:

    标签: jquery tinymce


    【解决方案1】:

    变量 activeEditor 在您第一次“激活/使用”它时被设置(比如点击它)。 如果您只使用一个编辑器,您可以使用tinymce.editors[0]

    tinymce.editors[0].setContent("hello world");
    

    在所有其他情况下,以这种方式使用 tinymce 实例对象

    tinymce.get('right').setContent("hello world");
    

    【讨论】:

    • 如果在一个页面上使用多个 tinymce 并使用索引 id 从 Jquery 填充(例如 id='my_txt[0]' ),那么第一个示例适用于所有示例,但第二个示例忽略了“0” (零)项
    • 删除我的评论 - 这些都适用于 TinyMCE4
    猜你喜欢
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 2014-07-19
    相关资源
    最近更新 更多