jQuery TinyMCE 4 - remove() 或 destroy()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17759111/
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
TinyMCE 4 - remove() or destroy()
提问by user007
I am using TinyMCE editor.I want to remove or destroy tinymce editors (Page contain more then one editor). Also remove classes and IDs added by tinyMCE.
我正在使用TinyMCE 编辑器。我想删除或销毁 tinymce 编辑器(页面包含多个编辑器)。还要删除 tinyMCE 添加的类和 ID。
But leave editable contents
但留下可编辑的内容
I tried :
我试过 :
tinymce.remove()
tinymce.destroy()
tinymce.execCommand('mceRemoveControl',true,'.editable');
Please note:
请注意:
my editor class is .editable
, And I have more then one editors in my page.
我的编辑器类是.editable
,而且我的页面中有多个编辑器。
采纳答案by Thariama
You need an editor id (which usually equals your editor html root elements id (in most cases a textarea)).
您需要一个编辑器 ID(通常等于您的编辑器 html 根元素 ID(在大多数情况下为 textarea))。
Example:
例子:
tinymce.execCommand('mceRemoveControl', true, 'my_original_textarea_id');
回答by assassinatorr
I had the same problem. In v4 all suggestions above did not work for me, but this did:
我有同样的问题。在 v4 中,上面的所有建议对我都不起作用,但这确实适用:
tinymce.remove("div.editable");
... regenerated HTML dynamicaly ...
tinymce.init(...);
I use inline editor:
我使用内联编辑器:
tinymce.init({
selector: "div.editable",
inline: true,
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
menubar: false,
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"});
Hope this helped
希望这有帮助
回答by Martin Sansone - MiOEE
Just in case anybody arrived here who is using the jQuery version of TinyMce use the following instead to remove an instance:
万一有人到达这里使用 TinyMce 的 jQuery 版本,请使用以下命令来删除实例:
$("#textarea_id").tinymce().remove();
回答by nikmauro
The following code is working
以下代码正在工作
tinymce.get(id).remove();
回答by Janak Bhatta
Simply use
只需使用
tinymce.remove()
to remove all editors.
删除所有编辑器。
回答by eithed
Bear in mind that if given textarea
has an id, tinyMCE will use it for some strange reason, even if selector
parameter has been used to apply editor to given element. This id is then used in internal array - tinyMCE.editors
which isn't cleared (isn't cleared if you'll use tinymce.execCommand('mceRemoveControl', true, [id])
, remove
actually removes editors
and prevents tinyMCE to be applied ever again). As such if you have a dynamic content with tinyMCE applied, it will work once, but never again. To resolve this you need to clean this array manually per delete tinyMCE.editors[$(node).getAttribute('id')]
请记住,如果给定textarea
有一个 id,tinyMCE 会出于某种奇怪的原因使用它,即使selector
参数已被用于将编辑器应用于给定元素。然后在内部数组中使用此 id -tinyMCE.editors
未清除(如果您将使用tinymce.execCommand('mceRemoveControl', true, [id])
,则不会清除,remove
实际上删除editors
并防止再次应用 tinyMCE)。因此,如果您有一个应用了 tinyMCE 的动态内容,它会工作一次,但不会再工作。要解决此问题,您需要手动清理此阵列delete tinyMCE.editors[$(node).getAttribute('id')]
回答by Michele Caggiano
You need simply use this code in order to remove all the editable textarea:
您只需使用此代码即可删除所有可编辑的文本区域:
tinyMCE.remove(".editable");
tinyMCE.remove(".editable");
Here more info about tinyMCE remove: http://archive.tinymce.com/wiki.php/api4:method.tinymce.EditorManager.remove.static
这里有关于 tinyMCE 删除的更多信息:http: //archive.tinymce.com/wiki.php/api4: method.tinymce.EditorManager.remove.static
回答by blacksunshineCoding
If you have multiple Instances of TinyMCE you can use following code snippet to close every instance of TinyMCE:
如果您有多个 TinyMCE 实例,您可以使用以下代码片段关闭每个 TinyMCE 实例:
for (var i = tinymce.editors.length - 1 ; i > -1 ; i--) {
var ed_id = tinymce.editors[i].id;
tinyMCE.execCommand("mceRemoveEditor", true, ed_id);
}
I use it before the Ajax Content is loaded.
我在加载 Ajax 内容之前使用它。
回答by george
tinymce.EditorManager.remove() This was working for me
tinymce.EditorManager.remove() 这对我有用
回答by JensB
Little late to the party but I recently added tinyMCE jQuery version to my angular project. For a few reasons I did not want to use the angular 3rd party code and just wanted the jQuery version to work.
聚会有点晚,但我最近在我的 angular 项目中添加了 tinyMCE jQuery 版本。出于一些原因,我不想使用 angular 3rd 方代码,只想让 jQuery 版本工作。
So here is my code for making TinyMCE 4.x work in angular, even with ng-repeat.
所以这是我的代码,即使使用 ng-repeat,也可以使 TinyMCE 4.x 以 angular 的方式工作。
All you have to do is decorate your textareas with the class "TinyMCEEditorBox" and call this method anytime you remove or add items that result in an update (such as more items being added to an ng-repeat).
您所要做的就是使用“TinyMCEEditorBox”类装饰您的文本区域,并在您删除或添加导致更新的项目(例如将更多项目添加到 ng-repeat)时调用此方法。
$scope.RebindTinyMCE = function ()
{
var tmceSelector = ".TinyMCEEditorBox";
for (var i = tinymce.editors.length - 1 ; i > -1 ; i--)
{
tinyMCE.execCommand("mceRemoveEditor", true, tinymce.editors[i].id);
}
setTimeout(function () {
$(tmceSelector).tinymce({
menubar: false,
statusbar: false,
toolbar: 'bold italic underline | alignleft aligncenter alignright | bullist numlist outdent indent | link',
});
}, 50);
}