使用JQuery设置CKEditor值

我有一个CKEditor textarea:

 

我有jQuery试图从数据库中设置值:

 $('#ContentPlaceHolder_taBody').val(substr[5]); 

不要担心我已经测试过它返回字符串的子字符串。 出于测试目的,我用“test”替换了子字符串,并且收到了同样的问题。

我知道围绕这一行的jquery不会影响它,因为我正在尝试填充其他文本字段。 就说到了ckeditor。

这是整个脚本:

 function (obj) { $.ajax({ type: "POST", url: "ContentSections.aspx/GetContentDetails", data: '{"nodeID": "' + obj.attr('id') + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var str = msg.d; var substr = str.split('|||'); $('#ContentPlaceHolder_hfContentSectionID').val(substr[0]); $('.txtAlias').val(substr[1]); $('.txtBrowserTitle').val(substr[2]); $('.txtMetaDescription').val(substr[3]); $('.txtMetaKeywords').val(substr[4]); $('#ContentPlaceHolder_taBody').val(substr[5]); } }); } 

问题是没有任何内容被填充,也没有显示javascript错误。

我试着四处看看但找不到任何帮助我的东西。 有没有人有任何想法?

您需要使用CKEditor的API。

具体来说, http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

阅读此链接后http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData ,以下代码为我工作。

 CKEDITOR.instances.editor1.setData( '

This is the editor data.

' );