ckeditor:“;这个.nodeName未定义“;错误(来自ckeditor.js),内联编辑器

ckeditor : "this.$.nodeName is undefined" error (from ckeditor.js), inline editor

本文关键字:ckeditor 编辑器 js 错误 这个 nodeName 未定义 来自      更新时间:2023-09-26

我是这个编辑的新手。所以,我在尝试一些非常简单的东西。我想内联编辑这个p元素。

<p class="h_text" >is your site working?</p>

所以,我有这个脚本

$(document).ready(function () {
            CKEDITOR.disableAutoInline = true;                
            var elementToEdit = $("body").find("p.h_text").first();
            console.log($(elementToEdit).length);
            console.log($(elementToEdit).html());                
            $(elementToEdit).attr('contenteditable', 'true');
            CKEDITOR.inline(elementToEdit);
        });

当我加载页面时,我收到了来自ckeditor.js 的错误

TypeError: this.$.nodeName is undefined

从2 console.log的输出中,我可以确认elementToEdit是有效的,而不是null。

我通过更改脚本中的这一行来完成这项工作

CKEDITOR.inline(elementToEdit);

到这个

$(elementToEdit).ckeditor();

老实说,我不太明白为什么这个有效,而第一个无效。如果有人解释一下会很有帮助。

试试这个,

var elementToEdit = $("body").find("p.h_text")[0];

取而代之的是

var elementToEdit = $("body").find("p.h_text").first();