CKEditor:如何销毁模糊实例?
我有一个 html 页面,上面有多个 div
元素。每次用户单击 div
时,它都会即时替换为 CKEditor
:
$('.editable').click(function() {
editor = CKEDITOR.replace(this);
});
现在,如果 CKEditor 实例失去焦点(模糊事件),我需要通过 ajax 将内容发布到单独的脚本(如果发生更改)并销毁此实例:
$('.editable').click(function() {
editor = CKEDITOR.replace(this);
editor.on('blur', function(e)
{
if (e.editor.checkDirty())
// get data with e.editor.getData() and do some ajax magic
e.editor.destroy();
});
});
但是此示例不起作用,因为我不知道为什么,之前会调用 destory()
checkDirty()
。我怎样才能让它发挥作用?
I have a single html page with multiple div
elements on it. Each time a user clicks on on a div
, it is replaced with an CKEditor
on the fly:
$('.editable').click(function() {
editor = CKEDITOR.replace(this);
});
Now, if the CKEditor instance loses its focus (blur event), I need to post the content to a separate script via ajax (if something changed) and destroy this instance:
$('.editable').click(function() {
editor = CKEDITOR.replace(this);
editor.on('blur', function(e)
{
if (e.editor.checkDirty())
// get data with e.editor.getData() and do some ajax magic
e.editor.destroy();
});
});
But this example won't work because, I don't know why, destory()
will be called before checkDirty()
. How can I get this working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将
destroy()
放在if()
语句中怎么样?您可以有一个 else 子句,如果没有任何更改,则调用 destroy。如果某些内容发生变化,您可以在数据传输后在 if 子句中调用destroy()
。或者您可以在调用
destroy()
之前检查变量。数据传输完成后并在 else 子句中将该变量设置为 true,这样在检查更改并传输任何更新的数据之前不会调用destroy()
。这是一个大纲,我还没有测试代码,但如果显示了概念。
祝你好运,
乔
How about if you put the
destroy()
inside theif()
statement? You could have an else clause that invokes destroy if nothing has changed. If something has changed, you can invokedestroy()
within the if clause once the data has been transfered.Or you could check a variable before invoking
destroy()
. Set that variable to true after the data transfer has been completed and in the else clause, that waydestroy()
won't be invoked until you've checked for changes and transfered any updated data.This is an outline, I haven't tested the code, but if shows the concept.
Be Well,
Joe