ckeditor + jquery + fancybox
目的是在我的管理页面上有一个小图标。 单击此图标将触发带有ckeditor textarea实例的模态窗口。 用户编辑文本,保存文本并关闭模态。 我的问题是,如果我再次点击图标,新的编辑器实例为空。 您可以在下面看到相关代码
HTML部分:
JS脚本:
$("#editShortText").fancybox({ 'scrolling': 'no', 'titleShow': false, 'onStart': function() { $('.jquery_texteditor').ckeditor(config); }, 'onComplete': function() { $('.jquery_texteditor').ckeditor(config); }, 'onClosed': function() { $('.jquery_texteditor').ckeditor(config); } }); $("#saveShortTextFrm").live("submit", function() { $.fancybox.showActivity(); $.ajax({ type : "POST", cache : false, url : "_save_text.php", data : $(this).serializeArray(), success: function(data) { if (data!='') { $("#shortTtextImageHolder").html(''); if(CKEDITOR.instances["jquery_texteditor"]) { delete CKEDITOR.instances["jquery_texteditor"]; $('.jquery_texteditor').ckeditor(config); $("#short_text_english").val(data); CKEDITOR.instances.short_text_english.setData(data); } } else { $("#shortTtextImageHolder").html('SOS'); } $.fancybox.close(); } }); return false; });
当我第一次点击我的链接/图像时,第一次点击一切正常。 如果我再次单击(保存模态数据或仅关闭模态窗口后),新模态将启动,但文本区域为空数据。
有想法该怎么解决这个吗?
当你关闭模态时尝试使用
CKEDITOR.instances.short_text_english.destroy(true);
要么
if (CKEDITOR.instances.short_text_english) { CKEDITOR.instances.short_text_english.setData(""); CKEDITOR.instances.short_text_english.destroy(true); }