简体   繁体   English

在textarea.value中保留换行符

[英]Preserving Linebreaks in textarea.value

I have to use textarea.value text but it does not preserve line breaks as input by the user. 我必须使用textarea.value文本,但它不能将换行符保留为用户输入的内容。 I don't want to use replace(/\\n\\r?/g, '<br />') trick as it is useful only to render text as html. 我不想使用replace(/\\n\\r?/g, '<br />')技巧,因为它仅用于将文本呈现为html有用。

Is there any other way to access textarea.value as it is? 是否有其他方法可以访问textarea.value?

在此示例http://jsfiddle.net/jfriend00/Gy7W3/中 ,在用户输入换行符的任何地方,文本区域都在.value属性上返回换行符,因此它似乎已经完成了您想要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery-.val到文本区域,不保留换行符 - jQuery - .val to a textarea not preserving linebreaks 使用 `textarea.value(&quot;&quot;)` 设置值会抛出“`TypeError`: `textarea.value` 不是函数” - Setting value with `textarea.value("")` throws “`TypeError`: `textarea.value` is not a function” textarea.selectionEnd 总是等于 textarea.value 中的最后一个字符 - textarea.selectionEnd is always equal to the last character in textarea.value 从 textarea 复制到 div,保留换行符 - Copy from textarea to div, preserving linebreaks 为什么textarea.value返回“未定义”? (使用本机Javascript) - Why is textarea.value returning “undefined”? (using Native Javascript) 复制粘贴表到chrome,textarea.value没有新行 - copy paste table to chrome, textarea.value no new lines 在p和textarea之间来回移动数据,但保留换行符 - Moving data back and forth between p and textarea, but preserving linebreaks 如何从流星中的可编辑div中选择值而不是使用textarea.value? - How do I select value from editable div in meteor instead of using textarea.value? 通过settimer-function将textarea.value存储到MySQL数据库,而不会丢失换行符 - Store textarea.value via settimer-function to MySQL database without losing newlines 使用PHP获取Javascript变量中具有换行符的textarea值 - Get textarea value having linebreaks in Javascript variable using PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM