在textarea中返回的回车符作为换行符 [英] carriage return in textarea retrieved as line feed
问题描述
如何在文本区域中保留回车符?
How can I preserve a carriage return character in a text area?
textarea.value = "X" + String.fromCharCode("13") + "X";
textarea.value.charCodeAt(1); //returns 10, not 13
请参阅此处: http://jsfiddle.net/vah9e/
推荐答案
According to W3C Textarea api value, it seems that when invoking the .value
attribute of textarea
, any carriage return or line feed is transformed into a LINE FEED (10) character (in fact W3C says CRFL
but it seems the browsers prefer only LF
) - so a script can be platform-independent on line feeds.
在表单数据中,精细的提要似乎转换为 CRLF
(13 + 10).
In a form data, it seems that the fine feeds are transformed into CRLF
(13+10).
W3C还谈到了原始值
,但它可能是任何javascript引擎的内部功能,并且似乎在Javascript中不可用.
W3C speaks also about a raw value
but it's probably internal to any javascript engine and it seems it's not available in Javascript.
这篇关于在textarea中返回的回车符作为换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!