使用 JQuery 设置 CKEditor 值

发布于 2024-10-28 19:30:02 字数 1242 浏览 1 评论 0原文

我有一个 CKEditor 文本区域:

 <textarea cols="80" id="taBody" name="taBody" class="ckeditor" rows="10" runat="server"></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 错误。

我尝试四处阅读,但找不到任何对我有帮助的东西。有人有什么想法吗?

I have a CKEditor textarea:

 <textarea cols="80" id="taBody" name="taBody" class="ckeditor" rows="10" runat="server"></textarea>

I have jQuery trying to set the value from the database:

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

Don't worry about the substring I already tested that it is returning a string. For testing purposes I replaced the substring with 'test' and was receiving the same issue.

I know that the jquery surrounding this line doesn't affect it because the other textfields I'm trying to populate work. Just when it comes to the ckeditor.

Here is the script in whole:

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]);
          }
     });
}

The issue was that nothing was being populated and no javascript errors were being shown.

I tried to read around but couldn't find anything that helped me. Does anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

有深☉意 2024-11-04 19:30:02

您需要使用 CKEditor 的 API 来代替。

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

You need to use CKEditor's API instead.

Specifically, http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

-黛色若梦 2024-11-04 19:30:02

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

CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );

After reading this link http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData, following code work for me.

CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );
幼儿园老大 2024-11-04 19:30:02
CKEDITOR.instances['IdOfCKEditorTextArea'].setData(value);

其中 value 就像你想要设置的 html 数据

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

where value is like you want set html data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文