CKEditor instance already exists

前端 未结 30 3440
刺人心
刺人心 2020-11-27 11:24

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

Whe

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 12:02

    I've prepared my own solution based on all above codes.

          $("textarea.ckeditor")
          .each(function () {
    
                    var editorId = $(this).attr("id");
    
                    try {    
                        var instance = CKEDITOR.instances[editorId];
                        if (instance) { instance.destroy(true); }
    
                    }
                    catch(e) {}
                    finally {
                        CKEDITOR.replace(editorId);
                    }
                });
    

    It works perfectly for me.

    Sometimes after AJAX request there is wrong DOM structure. For instace:

提交回复
热议问题