javascript 重置 TinyMCE 框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6099148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:26:40  来源:igfitidea点击:

Reset TinyMCE box

javascriptjqueryasp.nettinymce

提问by Rocky Singh

I am using TinyMCEeditor. I want to clear the content inside the editor box with some button click present on my form.

我正在使用TinyMCE编辑器。我想通过单击表单上的一些按钮清除编辑器框中的内容。

Can you let me know how to do so?

你能告诉我怎么做吗?

回答by Thariama

This can be easily done (no need to use the slow jQuery tinymce build) using the following code as onclick-action of your button:

这可以轻松完成(无需使用缓慢的 jQuery tinymce 构建),使用以下代码作为按钮的 onclick-action:

// '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(''); 

回答by DarthJDG

From the TinyMCE jQuery Plugin documentation, can be easily found from the page you linked:

TinyMCE jQuery 插件文档 中,可以从您链接的页面轻松找到:

// 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());

Try setting it to empty string, might be just what you need.

尝试将其设置为空字符串,可能正是您所需要的。

回答by user2570747

If you are interested in clearing the contentof the editor you can use: tinymce.get('#editorId').setContent('');// like others have suggested

如果您有兴趣清除编辑器的内容,可以使用: tinymce.get('#editorId').setContent(''); // 就像其他人建议的那样

However, if you'd like to reset the content and menu buttons etc. - essentially resetting the editor altogetheryou might consider using: tinymce.get('#editorId').init();

但是,如果您想重置内容和菜单按钮等 -基本上完全重置编辑器,您可以考虑使用: tinymce.get('#editorId').init();

回答by naspinski

$('#name_of_your_textarea').val('');