我正在升级到 CKEditor 版本 4.5.8。我使用 jQuery 访问 CKEditor API。
编辑器的文本区域不更新。我需要设置一个配置选项吗?
HTML:
<textarea name="mck_1" id="mck_1"> Enter text. </textarea>
<script> CKEDITOR.replace( 'mck_1' ); </script>
Javascript:
CKEDITOR.instances.mck_1.setData("Hello");
如何调试这个?我是否必须显式更新显示/文本区域?
如果我尝试手动更新 Firebug 中的文本区域,它会显示“未定义”。
CKEDITOR.instances.mck_1.setData("hi");
undefined
StackOverflow 中存在很多针对过去版本的 CKEditor 的“setData 不起作用”问题,但那里建议的解决方案都不适合我。
救命!
MMiz
编辑:我意识到文本区域上的第一个“setData”实际上有效。接下来的第二个不显示。从这里thread
1 : http://ckeditor.com/forums/Support/Second-Time-jQuery-Doesnt-Work似乎有一些时间上的事情。但据我所知,这就是。
最佳答案
我目前正在使用 ckeditor5,以上答案都不适合我。 基于document您可以使用以下代码行操作 ckeditor 的内部 html:
// A reference to the editor editable element in the DOM.
const domEditableElement = document.querySelector( '.ck-editor__editable' );
// Get the editor instance from the editable element.
const editorInstance = domEditableElement.ckeditorInstance;
// Use the editor instance API.
editorInstance.setData( '<p>Hello world!<p>' );
关于jquery - CKEditor 的 SetData 在版本 4 中不起作用 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37041333/