CKeditor实例为null还是未定义? [英] CKeditor instance is null or undefined?
本文介绍了CKeditor实例为null还是未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的屏幕上都显示了一个CKeditor,但是当我尝试获取编辑器的实例时,我的值为null或undefined,我该如何获取ckeditor实例,有人可以在这里帮助我吗
Hi all i have an CKeditor in my screen ckeditor is displaying but when i try to get the instance of the editor i have the value null or undefined how can i get the ckeditor instance can any one help me here
function editor() {
//i have null here
for (name in CKEDITOR.instances) {
CKEDITOR.instances[name].destroy()
}
var editor = CKEDITOR.instances.editor1;//i have null here
editor.on('key', function () {
var data = editor.getData();
});
}
$(document).ready(function () {
var editorShort = CKEDITOR.editor.replace('popup_editor1');
editor();
});
推荐答案
可能当时没有完全定义实例变量.根据您真正想对编辑器执行的操作,我建议您在instanceReady(这是CKEditor事件)中进行on键绑定和其他操作.
It could be that the instances variable is simply undefined at that time. Depending on what you really want to do with the editor, I suggest that you do the on key bindings and other such things inside instanceReady, which is a CKEditor event.
$(document).ready(function () {
// You can define it before replacing the editor
CKEDITOR.on('instanceReady', function(evt){
// Do your bindings and other actions here for example
// You can access each editor that this event has fired on from the event
var editor = evt.editor;
});
// replace editor
var editorShort = CKEDITOR.editor.replace('popup_editor1');
});
请参见 http://docs.ckeditor.com/#上的文档. !/api/CKEDITOR-event-instanceReady
这篇关于CKeditor实例为null还是未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文