可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
回答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