【问题标题】:tinymce getContent() returns "visual tab" string when "html" tab was opened当“html”选项卡打开时,tinymce getContent() 返回“visual tab”字符串
【发布时间】:2022-12-04 06:31:58
【问题描述】:

我的 tinymce 编辑器是动态初始化的:

wp.editor.initialize(jQuery(this).attr('id'), {
    mode : "exact",
        tinymce: {
            wpautop: true,
            plugins : 'charmap colorpicker hr lists paste tabfocus textcolor fullscreen wordpress wpautoresize wpeditimage wpemoji wpgallery wplink wptextpattern',
            toolbar1: 'formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,wp_more,spellchecker,fullscreen,wp_adv,listbuttons',
            toolbar2: 'styleselect,strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help',
            textarea_rows : 20
        },
        quicktags: {buttons: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close'},
        mediaButtons: true,
    });

一切都很好,除了当我试图获取内容时:

tinymce.editors[ xxxx ].getContent();

所以 tinymce 有两个选项卡,“visual”和“html”选项卡。上面那行返回输入到 VISUAL 选项卡中的文本,但如果我更改为 HTML 选项卡并修改文本,它仍然显示 VISUAL 选项卡! 如何解决?

【问题讨论】:

    标签: wordpress tinymce


    【解决方案1】:

    如果您使用的是 WordPress,则“HTML”选项卡实际上根本没有使用 TinyMCE,这就是尝试使用 TinyMCE API 获取数据失败的原因。

    在 Visual 和 HTML 选项卡之间切换是加载/删除 TinyMCE,这就是为什么您的 API 调用在可视模式下工作(TinyMCE 已加载)而不是在 HTML 中(TinyMCE 未加载)。

    【讨论】:

    • 我使用了“.isHidden()”调用,如果为真,我从 TEXTAREA 获取文本,否则为 .getContent()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    相关资源
    最近更新 更多