如何像html textarea换行符一样初始化CKEditor textarea换行符 [英] How to initialize CKEditor textarea line breaks as like html textarea line breaks

查看:63
本文介绍了如何像html textarea换行符一样初始化CKEditor textarea换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. HTML textareas可以识别换行符(输入按钮),并且我可以将元素的文本值保存到数据库中.然后我可以获取那些数据,将其设置在任何textarea上,但我仍然有换行符(直到这里没有问题).
  2. CKEditor文本区域在换行符后放置< p> < br/> .当我删除这些标签时,CKEditor无法识别换行符.
  1. HTML textareas can recognize line breaks (enter button) and i can save the element's text value into database. Then i can get those data, set it on any textarea, i still have line breaks (no problem until here).
  2. CKEditor textarea puts <p> or <br /> after line breaks. When i remove these tags, CKEditor cannot recognize there's a line break.

目的:我在CKEditor中使用了单词计数器插件,因此我需要像文本区域一样使用CKEditor.我需要纯文本值.

Purpose : I'm using a word counter plugin with CKEditor, so i need to use CKEditor as like a textarea. I need the plain text value.

到目前为止,我已经尝试过这些方法:

I tried these so far :

CKEDITOR.instances.editor1.document.getBody().getText()

是的,我可以正确获取文本值,将该值放在DB上,但是当我重新加载页面时,换行符消失了.因为ckeditor仅适用于html标签?

Yes i can get the text value correctly, i put this value on DB, but when i reload my page, the line breaks are gone. Because ckeditor works only with html tags ?

config.autoParagraph = false;


这只是删除内容开头的< p> 标记.

我需要纯文本+换行符.有什么建议么 ?还是我应该写下自己的课程?


This one just removes the <p> tag at the beginning of the content.

I need plain text+line breaks that's it. Any suggestions ? Or should i write down my own classes ?

推荐答案

Array.prototype.map
            .call(CKEDITOR.instances.editor1.document.getBody().$.childNodes,
                 function(item){
                  return item.innerText;
                  })
            .join("\n");

一个疯狂的答案,将< p> 块转换为以 \ n

Just a crazy answer to convert <p> blocks to a string separated by \n

这篇关于如何像html textarea换行符一样初始化CKEditor textarea换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆