JS获取CkEditor在线编辑的内容

Posted wuling129

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS获取CkEditor在线编辑的内容相关的知识,希望对你有一定的参考价值。

参考博文:【实践】获取CKEditor的html文本、纯文本、被选中的内容及赋值

1、获取CKEditor被选中的内容

var mySelection = CKEDITOR.instances.WORK_INTRODUCTION.getSelection();
        if (CKEDITOR.env.ie) {
            mySelection.unlock(true);
            data = mySelection.getNative().createRange().text;
        } else {
            data = mySelection.getNative();
        }
2、获取CKEditor纯文本
 var CText=CKEDITOR.instances.WORK_INTRODUCTION.document.getBody().getText(); //取得纯文本       

3、获取CKEditor带html标签的文本
var CHtml= CKEDITOR.instances.WORK_INTRODUCTION.getData();

4、给CKEditor赋值

CKEDITOR.instances.WORK_INTRODUCTION.setData("要显示的文字内容");

我的写法:

html中:

<asp:TextBox ID="txt_ProjectIntroduce" runat="server" TextMode="MultiLine" class="ckeditor" onKeyUp="isProjectIntroduceNull();" onblur="isProjectIntroduceNull();"></asp:TextBox>
                                    <script type="text/javascript">
                                        if (typeof CKEDITOR == \'undefined\') {
                                            document.write(\'加载CKEditor失败\');
                                        }
                                        else {
                                            var editor_ProjectIntroduce = CKEDITOR.replace(\'txt_ProjectIntroduce\');          // 创建编辑器
                                            CKFinder.setupCKEditor(editor, \'../../PlugIns/ckfinder/\');   // 为编辑器绑定"上传控件"
                                        }

 

js脚本:
str = CKEDITOR.instances.<%= txt_ProjectIntroduce.ClientID %>.document.getBody().getText(); //取得纯文本
              //str 长度默认为 1
              //alert("11" + str+ "22" + str.length );
              if (str.length <2) {
                  strSummary = strSummary + "项目介绍不能为空!";
              }

 

以上是关于JS获取CkEditor在线编辑的内容的主要内容,如果未能解决你的问题,请参考以下文章

CKEditor富文本编辑器踩坑-上传视频后无法删除视频和获取鼠标编辑状态光标

CKEditor富文本编辑器踩坑-上传视频后无法删除视频和获取鼠标编辑状态光标

CKEditor富文本编辑器踩坑-上传视频后无法删除视频和获取鼠标编辑状态光标

CKedit在线编辑器

Dropzone.js 无法从 HTML 编辑器 CKEDITOR 中获取值

ajax提交时 富文本CKEDITOR 获取不到内容