0

我试图在 jQuery 对话框中打开 ckeditor 第一次打开 ckeditor 框完美我再次单击它 jQuery 对话框加载 textarea 没有编辑器。

我假设它是因为我没有正确销毁它或重新初始化我不知道这是我尝试过的一些片段。

<script type="text/javascript">
if (CKEDITOR.instances['ContentText']) {
CKEDITOR.remove(CKEDITOR.instances['ContentText']);
}

CKEDITOR.replace('ContentText',
{

disableObjectResizing: true,
resize_enabled: false,
shiftEnterMode: CKEDITOR.ENTER_BR,
toolbarCanCollapse: false,
forcePasteAsPlainText: true
});
</script>

<script type="text/javascript">
if (CKEDITOR.instances.ContentText) {
CKEDITOR.instances.ContentText.destroy();

}

CKEDITOR.replace('ContentText',
{

disableObjectResizing: true,
resize_enabled: false,
shiftEnterMode: CKEDITOR.ENTER_BR,
toolbarCanCollapse: false,
forcePasteAsPlainText: true
});
</script>

这是部分视图中表单末尾的代码,我在视图中尝试编辑器销毁的对话框关闭功能中尝试过。如果您想查看实际代码,我可以部署它。

4

2 回答 2

0

可能发生的情况是您第二次打开对话框时没有初始化 CKeditor。第一次发生在页面加载时。但是第二次模态对话框可能会刷新 dom (html) 元素,而这些新元素并没有附加 ckeditor。

您可以通过在单击打开对话框时运行初始化代码来解决此问题。最好的方法是将您的 ckeditor 代码放入一个函数中,并将其添加到触发对话框的单击事件中。

但是由于您没有发布打开对话框的代码,所以我可能是错的。

于 2012-09-04T23:07:39.507 回答
0

尝试使用:

CKEDITOR.editor.prototype.destroy

代替

CKEDITOR.remove

此外,您应该编写一个在打开包含您的 CKE 代码的对话框时调用的函数(销毁和重新实例化实例)。

如果这两件事都没有帮助,您可以重命名 textarea 并使用您创建的新名称调用它:

var newCKname = "ContentText" + Math.floor((Math.random()*50)+1);
$('#ContentText').attr('id',newCKname);
[instantiate CKE again with the newCKname]
于 2012-09-04T23:09:28.950 回答