【发布时间】:2015-11-11 13:08:40
【问题描述】:
有什么方法可以计算在tinymce编辑器中输入的字符。我只想设置最低字符要求。或者如何为此目的正确使用tinyMCE.activeEditor.getContent()。
【问题讨论】:
标签: javascript jquery tinymce tinymce-4
有什么方法可以计算在tinymce编辑器中输入的字符。我只想设置最低字符要求。或者如何为此目的正确使用tinyMCE.activeEditor.getContent()。
【问题讨论】:
标签: javascript jquery tinymce tinymce-4
我相信更好的方法是使用getContent api:
// Get the HTML contents of the currently active editor
tinymce.activeEditor.getContent().length
// Get the raw text of the currently active editor
tinymce.activeEditor.getContent({format: 'text'}).length;
// Get content of a specific editor:
tinymce.get('content id').getContent().length
请注意第二个示例中 format 参数的用法,以便获取原始文本而不是带有 HTML 标记的解析文本。
【讨论】:
试试这个 ->
var body = tinymce.get("txtTinyMCE").getBody();
var content = tinymce.trim(body.innerText || body.textContent);
return content.length;
【讨论】: