从tinyMCE中删除字符

时间:2014-06-24 14:18:21

标签: javascript jquery

我正在使用tinyMCE,无论你在一个盒子里输入什么内容都显示在一个tinyMCE框中,我正在通过tinyMCE.get('idname').getContent();检索数据,但是它显示的文本为<p>text</p>我将如何删除这些p从我的文字?

2 个答案:

答案 0 :(得分:2)

您需要将format选项设置为text传递给getContent函数:

var textOnly = tinyMCE.get('idname').getContent({format : 'text'});

在这个小提琴中展示:http://fiddle.tinymce.com/8leaab

答案 1 :(得分:0)

如果.getContent({format:'text'}) doesn't work,请尝试以下操作:

var editor = tinyMCE.get('idname').getBody();
var text;
if(editor.textContent)
    text = editor.textContent;
else if(editor.innerText)
    text = editor.innerText;

或者因为您正在使用jQuery

var editor = tinyMCE.get('idname').getBody();
var text;
text = $(editor).text();