如何使用jquery向ckeditor添加额外数据?

我正在研究MVC3 CKeditor,当我点击提交按钮时,我需要在CKeditor中插入一些额外的数据。 我怎样才能做到这一点? 到目前为止我的代码如下:这是我的html页面

@Html.TextAreaFor(m => m.Message, new { Class = "input-xlarge", @id = "txtAreasocial",@rows="3" })
$(document).ready(function () { //Passing the Text Area reference to get the CK Editor var editor = CKEDITOR.editor.replace('txtAreasocial'); }); $('#btnadd').click(function () { alert('hi'); var data = "Hello. This is a new node."; alert(data); CKEDITOR.editor.setData(data); editor.setData(data) });

我不太确定你有多少CKeditor实例。 您需要获取编辑器的实例并使用setData方法将数据添加到特定实例。 例如:

 CKEDITOR.instances['editor1'].setData(data) 

要么

 CKEDITOR.instances.editor1.setData(data) 

检查文档中的setData方法。

使用“insertHtml”或“insertText”函数将数据附加到CKEDITOR。 像这样:

 CKEDITOR.instances['input-text-area-ID'].insertHtml(data); 
  • 制作一个新的子元素

     var txtNode = document.createTextNode("Hello. This is a new node."); 
  • 然后将其附加到您的编辑器中..

     txtNode.appendTo($('#editor'));