How do I set a value in CKEditor with Javascript?

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

I am wondering how I can set a value in CKEditor using Javascript?

I have tried the following, but neither of them work...

document.[form name].[textarea name].value=data; $('#textareaID').val(data);

However, both these work without the editor applied. Is there a way I can do this with the editor?

回答1:

Use the CKEditor method setData():

CKEDITOR.instances[**fieldname**].setData(**your data**)


回答2:

The insertHtml() and insertText() methods will insert data into the editor window, adding to whatever is there already.

However, to replace the entire editor content, use setData().



回答3:

Use insertHtml() or insertText() method.



回答4:

I have used the below code and it is working fine as describing->

CKEDITOR.instances.mail_msg.insertText(obj["template"]);

Here-> CKEDITOR ->Your editor Name, mail_msg -> Id of your textarea(to which u bind the ckeditor), obj["template"]->is the value that u want to bind



回答5:

Try This

CKEDITOR.instances['textareaId'].setData(value);


回答6:

Sets the editor data. The data must be provided in the raw format (HTML). CKEDITOR.instances.editor1.setData( 'Put your Data.' ); refer this page



回答7:

Take care to strip out newlines from any string you pass to setData(). Otherwise an exception gets thrown.

Also note that even if you do that, then subsequently get that data again using getData(), CKEditor puts the line breaks back in.



回答8:

Let try this..

Update :

To set data :

Create instance First::

var editor = CKEDITOR.instances['editor1'];

Then,

editor.setData('your data');

or

editor.insertHtml('your html data');

or

editor.insertText('your text data');  

And Retrieve data from your editor::

editor.getData();

If change the particular para HTML data in CKEditor.

var html = $(editor.editable.$); $('#id_of_para',html).html('your html data');

These are the possible ways that I know in CKEditor



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!