如何在jQuery中获取tinymce内容? [英] How to get tinymce content in jquery?

查看:568
本文介绍了如何在jQuery中获取tinymce内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取tinymce数据,但是遇到tinymCE未定义的错误.这是我的代码:

i am trying to get tinymce data but getting tinyMCE undefined error. Here is my code:

function savePost( ){ 

    console.log(  jQuery('#wp_tinymce_editor').tinyMCE().getContent() );
}

请检查

推荐答案

TinyMCE对象/库是负责您的编辑器的对象,因此您应该使用该对象来获取内容.

TinyMCE object/library is the one the responsible for your Editor, so you should use that object to get the content.

您可以为此使用activeEditor,或者(出于某种原因)如果您具有在jQuery对象中创建编辑器的原始元素,则可以使用该jQuery对象获取原始元素的id并使用它来获取TinyMCE的内容(使用TinyMCE编辑器).

You can use the activeEditor for that, or if (for some reason) you have the original element that created the editor in a jQuery object, you can use that jQuery object to get the id of the original element and use that in order to get the content of the TinyMCE (using the TinyMCE editor).

仅适用于jQuery-您永远不要使用此功能

如果出于某种原因您真的只需要使用jQuery(并且我真的不明白为什么),则可以使用与_ifr串联的原始元素的id并获取内容.使用此选项可能会给您带来不希望的结果,因为tinymce将标签添加到dom中存在的html中,但在调用getContent函数时将其删除.

If for some reason you really have to use only jQuery for that (and I really don't understand why), you can use the id of the original element, concatenated with _ifr and get the content. Using this option will probably give you don't want, because tinymce add tags to the html that exists in the dom but stripped when calling the getContent function.

以下是3个选项的示例:

Here is an example for the 3 options:

$('#btn1').click(function() {
    console.log(tinyMCE.activeEditor.getContent());
});
$('#btn2').click(function() {
    console.log(tinyMCE.editors[$('#ta').attr('id')].getContent());
});
$('#btn3').click(function() {
    alert('You should really NOT use this option');
    console.log($('#ta_ifr')[0].contentDocument.body.innerHTML);
});

这是一个有效的示例: https://jsfiddle.net/8tdf3q22/

Here is a working example: https://jsfiddle.net/8tdf3q22/

这篇关于如何在jQuery中获取tinymce内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆