如何将数据加载到ckeditor onload中(How to load data into ckeditor onload)

编程入门 行业动态 更新时间:2024-10-28 03:29:01
如何将数据加载到ckeditor onload中(How to load data into ckeditor onload)

是否可以在不使用JQuery的情况下将数据加载到ckeditor中? 如果可能,我想使用内联脚本标记。 我可以找到的所有例子都与Jquery相关,这对我来说不是最优的。

到目前为止,我在CK网站上找到的例子是:

CKEDITOR.instances.editor1.setData( '<p>Some other editor data.</p>', function() { this.checkDirty(); // true });

我试图用内联脚本标记来使用它,但它使编辑器崩溃。 如果我在JQuery中使用它,它将按预期工作。

Is it possible to load data into the ckeditor without using JQuery? I would like to use an inline script tag for this if possible. All of the examples I can find deal with Jquery and that isn't optimal in my case.

What I have so far is the example I found on CKs site:

CKEDITOR.instances.editor1.setData( '<p>Some other editor data.</p>', function() { this.checkDirty(); // true });

I've tried to use this with an inline script tag but it crashes the editor. If I use this in JQuery, it will work as expected.

最满意答案

这里是一个使用CKEDITOR API而不使用jQuery的例子。 请注意调用替换函数,该函数用textarea内容初始化CKEDITOR的“editor1”实例。 我认为这将是填充内容的最简单方式,但如果这还不够,可以看到我在你的问题中使用了代码,用“其他编辑器数据”填充了CKEDITOR。

HTML:

<textarea id="editor1"> Hello, world! </textarea>​

使用Javascript:

CKEDITOR.replace( 'editor1', { toolbar: 'Basic', uiColor: '#9AB8F3' }); CKEDITOR.instances.editor1.setData( '<p>Some other editor data.</p>', function() { this.checkDirty(); // true });

http://jsfiddle.net/cDzqp/

Here is an example using CKEDITOR API without using jQuery. Please observe the call to replace function which initializes the "editor1" instance of the CKEDITOR with the textarea content. I think that would be the easiest way to populate the content onload, but if that will not suffice, you can see I've used the code in your question to populate the CKEDITOR with "Some other editor data."

HTML:

<textarea id="editor1"> Hello, world! </textarea>​

Javascript:

CKEDITOR.replace( 'editor1', { toolbar: 'Basic', uiColor: '#9AB8F3' }); CKEDITOR.instances.editor1.setData( '<p>Some other editor data.</p>', function() { this.checkDirty(); // true });

http://jsfiddle.net/cDzqp/

更多推荐

本文发布于:2023-08-04 21:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1421367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   加载   数据   ckeditor   load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!