javascript 多次 AJAX 刷新和 TinyMCE 出现问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14971384/
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-26 23:02:57  来源:igfitidea点击:

Having issues with Multiple AJAX refresh and TinyMCE

javascriptjqueryajaxtinymce

提问by BostonMacOSX

So I'm running into this predicament.

所以我遇到了这个困境。

<SCRIPT src="../js/tiny_mce/tiny_mce.js"></script>
<SCRIPT type="text/javascript">
   tinyMCE.init({
        mode : "textareas",
        theme : "simple"
   });
</SCRIPT>
<SCRIPT src="../js/admin.js"></script>

The above is called on my PHP page.

以上是在我的 PHP 页面上调用的。

I'm then calling

然后我打电话

var request = $.ajax(
{
   url:"getEvents.php",
   type:"POST",
   data:{'method':'showevents'},
   dataType:"html"
   }).done(function(msg){
        $('#eventlistbody').html(msg);
   }); 

   setTimeout(
        function(){
            $(".mceSimple").each(function(){
              tinyMCE.execCommand("mceAddControl",false, this.id);
           })
   },2000); 

this loads a bunch of textareas..... the tinyMCE will load on all the text areas the first time it returns..when I click on the reload which runs the above again and returns the text areas they no longer have the tinyMCE attached to them. I'm not sure why it works the first time and not subsequent times.

这会加载一堆文本区域..... tinyMCE 将在第一次返回时加载所有文本区域..给他们。我不确定为什么它第一次工作而不是随后的时间。

回答by Thariama

You should shut down tinymce correctly before you reload in order to be able to reinitialize a tinymce editor after the reload has been made. This is necessary because tinymce does not like to be dragged around the dom. And initialized editor instances may have one one unique id (using reload will force tinymce to try to initliaze a second editor with the same id - which will fail).

您应该在重新加载之前正确关闭 tinymce,以便能够在重新加载后重新初始化 tinymce 编辑器。这是必要的,因为 tinymce 不喜欢在 dom 周围拖动。并且初始化的编辑器实例可能有一个唯一的 id(使用 reload 将强制 tinymce 尝试初始化具有相同 id 的第二个编辑器 - 这将失败)。

Tinymce3:To shut down an edtor instance use:

Tinymce3:要关闭编辑器实例,请使用:

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

To reinitialize use

重新初始化使用

tinymce.execCommand('mceAddControl',true, editor_id);

Tinymce4:To shut down an edtor instance use:

Tinymce4:要关闭编辑器实例,请使用:

tinymce.execCommand('mceRemoveEditor',true,editor_id);

To reinitialize use

重新初始化使用

tinymce.execCommand('mceAddEditor',true,editor_id);

回答by Andre

For me tinyMCE.remove(editor_id) worked.

对我来说 tinyMCE.remove(editor_id) 工作。

回答by Uriel Acosta Hernández

Tinymce4: To shut down an edtor instance use:

Tinymce4:要关闭编辑器实例,请使用:

tinymce.remove(); 

or indicate one unique id

或指定一个唯一 ID

tinymce.execCommand('mceRemoveEditor',true,editor_id);

To reinitialize use

重新初始化使用

tinymce.init(conftinymce);

or indicate one unique id

或指定一个唯一 ID

tinymce.execCommand('mceAddEditor',true,editor_id);