我正在开发一个使用CKEditor的项目。我有一个包含多个属性的面板来创建工具提示。我选择CKEditor将内容插入到工具提示中,因为它非常适合用户。
如果我使用普通的textarea插入我想要的内容,一切正常。但相反,我想使用CKEditor正常textarea。我不知道发生了什么,但工具提示没有得到我写的内容。
有人可以帮我吗?
// 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>
我已经阅读了有关插入ckeditor.instances
等等的JavaScript代码,但我无法弄清楚它是如何工作的。
答案 0 :(得分: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">
答案 1 :(得分:1)
CKEditor库注册global variable(对象)CKEDITOR
(指window.CKEDITOR
):
console.log( CKEDITOR );
> Object {...}
当您create an instance时,我们说CKEDITOR.replace()
,它已在CKEDITOR.instances
object中注册。此对象中的键对应于实例的名称。
console.log( CKEDITOR.instances.editor1 );
> Object {...}
这是您访问编辑器API的方式,直到您销毁它为止。因此,如果您想从编辑器中retrieve data,请致电:
console.log( CKEDITOR.instances.editor1.getData() );
> "<p>Some text</p>"
如果你想使用jQuery来玩CKEditor,那么CKEditor API就有official wrapper (adapter)。
另外,考虑到您希望使用CKEditor为某些工具提示生成HTML,您可能希望避免通过编辑器创建段落(默认行为)。您可以将configuration option:config.enterMode
设置为CKEDITOR.ENTER_BR
来实现。有关配置CKEditor的信息,请参阅the article。