Jquery CKeditor实例为空或未定义?
大家好,我的屏幕上有一个CKeditor,CKeditor正在显示,但当我尝试获取编辑器实例时,我的值为null或undefined。我如何获取CKeditor实例这里有人能帮我吗Jquery CKeditor实例为空或未定义?,jquery,ckeditor,Jquery,Ckeditor,大家好,我的屏幕上有一个CKeditor,CKeditor正在显示,但当我尝试获取编辑器实例时,我的值为null或undefined。我如何获取CKeditor实例这里有人能帮我吗 function editor() { //i have null here for (name in CKEDITOR.instances) { CKEDITOR.instances[name].destroy() } var editor = CKEDITOR
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();
});
可能是instances变量当时没有定义。根据您真正想对编辑器执行的操作,我建议您在InstanceRady中执行on键绑定和其他类似操作,InstanceRady是一个CKEditor事件
$(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');
});
请参阅Nenotlep上的文档。答案很好,我只是补充了一些东西来帮助像我这样的人
<script type="text/javascript">
$(document).ready(function () {
CKEDITOR.on('instanceReady', function(evt){
console.log("instance is ready");
for (var instance in CKEDITOR.instances)
CKEDITOR.instances[instance].updateElement();
$(文档).ready(函数(){
CKEDITOR.on('instancerady',函数(evt){
log(“实例已准备就绪”);
例如(CKEDITOR.instances中的var实例)
CKEDITOR.instances[instance].updateElement();
//现在,如果您执行console.log(instance),它将为编辑器或id\u提供您的编辑器,请使用此值
var slug= $('#slugfield').val()
var e=CKEDITOR.instances.id_Your_Message
e.on('keyup', function(e){
var content = CKEDITOR.instances[instance].getData()
$.ajax({
type: "POST",
url: "{% url 'edit-update' %}",
data: {'slug':newslug,'code':content},
success: function (data) {
console.log("instance is");
console.log(instance);
},
error: function(data) {
console.log("error");
}
});
});
});
});
</script>
var slug=$('#slugfield').val()
var e=CKEDITOR.instances.id\u您的消息
e、 on('keyup',功能(e){
var content=CKEDITOR.instances[instance].getData()
$.ajax({
类型:“POST”,
url:“{%url'编辑更新'%}”,
数据:{'slug':newslug,'code':content},
成功:功能(数据){
log(“实例是”);
console.log(实例);
},
错误:函数(数据){
控制台日志(“错误”);
}
});
});
});
});