gpt4 book ai didi

javascript - 删除 TinyMCE 控件并重新添加

转载 作者:太空狗 更新时间:2023-10-29 13:54:51 26 4
gpt4 key购买 nike

我有一个从不重新加载页面的 js 应用程序,因此在导航时我需要完全删除 TinyMCE 控件,然后在导航到需要它的区域时我想重新初始化。我尝试了这个问题的公认答案,但它似乎什么也没做。

How do i remove tinyMCE and then re-add it?

 tinymce.EditorManager.execCommand('mceRemoveControl',true, editor_id);

和我的具体实现:

  //if I throw an alert here, it does get called, so I know it's not null
if (tinyMCE.getInstanceById("main-text"))
tinyMCE.EditorManager.execCommand('mceRemoveControl', true, "main-text");

我也试过

  tinyMCE.remove( tinyMCE.getInstanceById("main-text"));
// AND
tinyMCE.remove( "main-text");

我知道当我在条件条件中放置警报时该语句会被执行...我知道那是正确的 ID -- API 中是否还有其他我遗漏的东西?这不是 jQuery 版本。编辑器在删除尝试后仍然存在,如果我通过导航回到带有表单的状态重新初始化它,我什至会得到一个具有相同 ID 的新编辑器。

编辑:下面的解决方案不适用于当前版本 3.5b3,仅适用于 3.4.9。存在“t 未定义”的错误

以防万一,这是 init 之后 DOM 的相关部分。

 <textarea id="main-text" style="display: none;" aria-hidden="true"></textarea>
<span id="main-text_parent" class="mceEditor defaultSkin" role="application" aria-labelledby="main-text_voice" style="display: inherit;">
<span id="main-text_voice" class="mceVoiceLabel" style="display:none;">Rich Text Area</span>
<table id="main-text_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 100%; height: 400px;">
<tbody>
<tr class="mceFirst" role="presentation">
<td class="mceToolbar mceLeft mceFirst mceLast" role="presentation">
<div id="main-text_toolbargroup" aria-labelledby="main-text_toolbargroup_voice" role="group" tabindex="-1">
<span role="application">
</div>
<a onfocus="tinyMCE.getInstanceById('main-text').focus();" title="Jump to tool buttons - Alt+Q, Jump to editor - Alt-Z, Jump to element path - Alt-X" accesskey="z" href="#"></a>
</td>
</tr>
<tr>
<tr class="mceLast">
</tbody>
</table>
</span>

最佳答案

任何看到这篇文章的人。现在 tinymce 4.X 支持通过调用 remove 函数删除编辑器或编辑器表单页面。

http://www.tinymce.com/wiki.php/api4:method.tinymce.remove

// Remove all editors bound to divs
tinymce.remove('div');

// Remove all editors bound to textareas
tinymce.remove('textarea');

// Remove all editors
tinymce.remove();

// Remove specific instance by id
tinymce.remove('#id');

关于javascript - 删除 TinyMCE 控件并重新添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com