1

我正在开发一个使用 CKEditor 的项目。我有一个包含多个属性的面板来创建工具提示。我选择 CKEditor 将内容插入到工具提示中,因为它对用户非常有用。

如果我使用普通的文本区域插入我想要的内容,一切正常。但是我想使用 CKEditor 代替普通的文本区域。我不知道发生了什么,但工具提示没有得到我写的内容。

有人可以给我手吗?

// Normal textarea, this works
<textarea id="editor1" autocomplete="off"></textarea>

CKEditor 的脚本:

<textarea id="editor1" name="editor1" autocomplete="off"></textarea>
<script type="text/javascript">
    CKEDITOR.replace( 'editor1' );
</script>

我已经阅读了要插入的 JavaScript 代码ckeditor.instances……等等,但我不知道它是如何工作的。

4

2 回答 2

1

CKEditor library registers a global variable (object) CKEDITOR (refers to window.CKEDITOR):

console.log( CKEDITOR );
> Object {...}

When you create an instance, let's say with CKEDITOR.replace(), it's registered in CKEDITOR.instances object. The key in this object corresponds to the name of the instance.

console.log( CKEDITOR.instances.editor1 );
> Object {...}

This is the way you access the API of your editor, until you destroy it. So if you want to retrieve data from your editor, basically call:

console.log( CKEDITOR.instances.editor1.getData() );
> "<p>Some text</p>"

If you want to use jQuery to play with CKEditor, there's an official wrapper (adapter) for CKEditor API.

Also, considering the fact that you want to use CKEditor to produce HTML for some tooltip, you may want to avoid creating paragraphs by the editor (default behavior). You can do that by setting the configuration option: config.enterMode to CKEDITOR.ENTER_BR. See the article about configuring CKEditor.

于 2013-08-01T21:10:55.143 回答
1

试试这个代码

文档

$('#editor1').ckeditor(); // to add ckeditor to textbox

$('#editor1').val(); // fetching value from textbox

不要忘记添加jQuery文件

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/ckeditor/adapters/jquery.js">
于 2013-08-01T16:30:03.220 回答