如何获取jquery中的tinymce内容?
How to get tinymce content in jquery?
我正在尝试获取 tinymce 数据,但收到 tinyMCE 未定义错误。这是我的代码:
function savePost( ){
console.log( jQuery('#wp_tinymce_editor').tinyMCE().getContent() );
}
请检查
TinyMCE object/library 负责您的编辑器,因此您应该使用该对象来获取内容。
您可以为此使用 activeEditor
,或者如果(出于某种原因)您有在 jQuery 对象中创建编辑器的原始元素,您可以使用 jQuery 对象获取原始元素的 id
并使用它来获取 TinyMCE 的内容(使用 TinyMCE 编辑器)。
Only with jQuery - You should never use this
如果出于某种原因你真的必须只使用 jQuery(我真的不明白为什么),你可以使用原始元素的 id,与 _ifr
连接并获取内容。使用这个选项可能会给你不想要的,因为 tinymce 将标签添加到存在于 dom 但在调用 getContent
函数时被剥离的 html。
以下是 3 个选项的示例:
$('#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/
<textarea class="tinymce" id="texteditor"></textarea>
在jquery中,你可以这样做。
var content = tinymce.get("texteditor").getContent();
Html文本编辑器文本代码:
<textarea name="description" class="tinymce" id="texteditor"></textarea>
您可以像这样使用 javascript 打印 TinyMCE 文本编辑器代码。
var content = tinymce.get("texteditor").getContent();
alert(descriptionFieldTxt);
输出:
带标签的输出
现在你可以像这样打印没有 p 标签的 tinymce texteditor 值
var content = tinymce.get("texteditor").getContent({format: "text"});
alert(descriptionFieldTxt);
此代码打印不带标签的文本:
我正在尝试获取 tinymce 数据,但收到 tinyMCE 未定义错误。这是我的代码:
function savePost( ){
console.log( jQuery('#wp_tinymce_editor').tinyMCE().getContent() );
}
请检查
TinyMCE object/library 负责您的编辑器,因此您应该使用该对象来获取内容。
您可以为此使用 activeEditor
,或者如果(出于某种原因)您有在 jQuery 对象中创建编辑器的原始元素,您可以使用 jQuery 对象获取原始元素的 id
并使用它来获取 TinyMCE 的内容(使用 TinyMCE 编辑器)。
Only with jQuery - You should never use this
如果出于某种原因你真的必须只使用 jQuery(我真的不明白为什么),你可以使用原始元素的 id,与 _ifr
连接并获取内容。使用这个选项可能会给你不想要的,因为 tinymce 将标签添加到存在于 dom 但在调用 getContent
函数时被剥离的 html。
以下是 3 个选项的示例:
$('#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/
<textarea class="tinymce" id="texteditor"></textarea>
在jquery中,你可以这样做。
var content = tinymce.get("texteditor").getContent();
Html文本编辑器文本代码:
<textarea name="description" class="tinymce" id="texteditor"></textarea>
您可以像这样使用 javascript 打印 TinyMCE 文本编辑器代码。
var content = tinymce.get("texteditor").getContent();
alert(descriptionFieldTxt);
输出:
带标签的输出
现在你可以像这样打印没有 p 标签的 tinymce texteditor 值
var content = tinymce.get("texteditor").getContent({format: "text"});
alert(descriptionFieldTxt);
此代码打印不带标签的文本: