【发布时间】:2011-08-31 05:54:23
【问题描述】:
我正在使用TinyMCE 编辑器。我想通过我的表单上的一些按钮单击来清除编辑器框中的内容。
你能告诉我怎么做吗?
【问题讨论】:
标签: javascript jquery asp.net tinymce
我正在使用TinyMCE 编辑器。我想通过我的表单上的一些按钮单击来清除编辑器框中的内容。
你能告诉我怎么做吗?
【问题讨论】:
标签: javascript jquery asp.net tinymce
将指定的内容设置为编辑器实例,这将在设置内容之前清理内容 不同的清理规则选项。
tinymce.activeEditor.setContent('');
【讨论】:
如果您有兴趣清除编辑器的内容,您可以使用: tinymce.get('#editorId').setContent(''); // 就像其他人建议的那样
但是,如果您想重置内容和菜单按钮等 - 基本上完全重置编辑器,您可以考虑使用: tinymce.get('#editorId').init();
【讨论】:
$('#name_of_your_textarea').val('');
【讨论】:
使用以下代码作为按钮的 onclick-action 可以轻松完成(无需使用缓慢的 jQuery tinymce 构建):
// 'content' is tinymce default,
// but if your textarea got an ID that is the one you need!
var my_editor_id = 'content';
// set the content empty
tinymce.get(my_editor_id).setContent('');
【讨论】:
my_editor_id 应该真正命名为 my_textarea_id。当我阅读 editor 时,我想到了 tinymce 编辑器 :-)
tinymce.get('content').setContent('');
setTimeout 匿名函数中调用它,超时为 0。否则它不起作用,并且由于某种原因我在 JS 控制台中遇到了各种错误。只是觉得我应该提一下。
来自TinyMCE jQuery Plugin documentation,可以从您链接的页面轻松找到:
// Will change the contents of an textarea with the ID "someeditor"
$('#someeditor').html('Some contents...');
// Will change the contents all text areas with the class tinymce
$('textarea.tinymce').html('Some contents...');
// Gets the contents from a specific editor
alert($('#someeditor').html());
尝试将其设置为空字符串,可能正是您所需要的。
【讨论】: