开发者

Reset TinyMCE box

开发者 https://www.devze.com 2023-03-08 00:44 出处:网络
I am using TinyMCE editor. I want to clear the content inside the editor box with some button click pr开发者_Go百科esent on my form.

I am using TinyMCE editor. I want to clear the content inside the editor box with some button click pr开发者_Go百科esent on my form.

Can you let me know how to do so?


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

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


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

// 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.


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

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


Sets the specified content to the editor instance, this will cleanup the content before it gets set using the different cleanup rules options.

tinymce.activeEditor.setContent('');


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

精彩评论

暂无评论...
验证码 换一张
取 消