微信号:
当前位置:首页 > 资讯文摘 > 新闻资讯

ckeditor获取纯文本,ckeditor过滤html代码

2015/6/18 23:12:12

$("#submit").click(function () {
             /* CKEDITOR.replace("editor1"); */
             var title = $("#caption").val(); /*不能用.text()或.html()*/
             var val = CKEDITOR.instances.editor1.getData();
             var content = editor.document.getBody().getText();
             /* var editor = CKEDITOR.replace("editor1");
            editor.document.getBody().getText(); //取得纯文本
            editor.document.getBody().getHtml(); //取得html文本
             var valText = CKEDITOR.instances.editor1.EditorDocument.body.innerText(); */
            if (title.length == 0 || val.length == 0) {
                       alert("标题或内容不能为空");
             } else {
                      alert("标题:" + title + "内容" + content + "html内容:" + val);
                          }
});


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();

相关新闻: