作者:捕鱼达人qq怎么刷金币 | 来源:互联网 | 2023-05-28 09:26
IhaveadivwiththeattributecontentEditableset.我有一个div属性contentEditable设置。Thisallowsmeto
I have a div with the attribute contentEditable set.
我有一个div属性contentEditable设置。
This allows me to have a free-form editable textarea, without the need for any form input fields: http://jsfiddle.net/M8wx9/8/
这允许我有一个自由格式的可编辑textarea,而不需要任何表单输入字段:http://jsfiddle.net/M8wx9/8/
However, when I create a couple of new lines and click save button, I grab the content with the .text()
method which goes on to remove the line feeds I just entered. I need to maintain the newline characters if at all possible and store the content as plain text in the database.
但是,当我创建几个新行并单击“保存”按钮时,我使用.text()方法获取内容,该方法继续删除我刚刚输入的换行符。如果可能的话,我需要维护换行符,并将内容作为纯文本存储在数据库中。
I could store the HTML directly to the database by using .html()
instead of .text()
but I don't like that idea as I may need to extract this data as plain text in the future. Furthermore, pressing enter in Firefox breaks new lines with
, Chrome and Safari are breaking with ...
and Internet Explorer and Opera are using paragraphs ...
for new lines, so it doesn't sound very easy to be able to parse the html.
我可以使用.html()而不是.text()将HTML直接存储到数据库中,但我不喜欢这个想法,因为我可能需要将此数据提取为未来的纯文本。此外,在Firefox中按Enter键会打破新的行,Chrome和Safari正在打破
...
,Internet Explorer和Opera正在使用段落
...
线条,所以听起来很难解析html。
How can I preserve these line feeds and store the content as plain text in the database (Similar to the way a textarea does)?
如何保留这些换行符并将内容作为纯文本存储在数据库中(类似于textarea的方式)?
Best Regards, ns
最诚挚的问候,ns
3 个解决方案