永发信息网

获取ckeditor的内容

答案:1  悬赏:40  手机版
解决时间 2021-11-27 18:21
  • 提问者网友:饥饿走向夜
  • 2021-11-27 08:35
获取ckeditor的内容
最佳答案
  • 五星知识达人网友:低血压的长颈鹿
  • 2021-11-27 09:19
1、获取CKEditor被选中的内容
var mySelection = CKEDITOR.instances.ckStem.getSelection();
if (CKEDITOR.env.ie) {
mySelection.unlock(true);
data = mySelection.getNative().createRange().text;
} else {
data = mySelection.getNative();
}
2、获取CKEditor纯文本
var stemTxt=CKEDITOR.instances.CKEditor1.document.getBody().getText(); //取得纯文本
3、获取CKEditor带HTML标签的文本
var stem = CKEDITOR.instances.CKEditor1.getData();追问不要在其他地方复制追答ckeditor支持绑定change事件,例如:


    summary_editor = CKEDITOR.replace("task_summary");
    summary_editor.on( 'change', function( event ) {
        var data = this.getData(); //获取editor中的内容
        console.log(data+' '+data.length)
    });
在输入时,可以得到输入的内容。图中为如上代码输入时的控制台log

追问为什么是包裹在p中的,

我现在想做的事情是,统计CKeditor中的字符数量,以达到限制输入字符数的目的,求帮助啊追答你可以自己去HTML呀,那是另外的问题了追问用innerHTML和textContent都取不到p的内容,能加一下q吗追答    summary_editor.on( 'change', function( event ) {
        var data = this.getData(); //获取editor中的内容,带html
        data = this.document.getBody().getText(); //纯文本不带html
        console.log(data+' '+data.length)
    });用 getText() 可以拿到纯文本

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯