carriage return in textarea retrieved as line feed

后端 未结 1 1210
Happy的楠姐
Happy的楠姐 2021-01-13 13:39

How can I preserve a carriage return character in a text area?

textarea.value = \"X\" + String.fromCharCode(\"13\") + \"X\";
textarea.value.charCodeAt(1); //         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 14:31

    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.

    In a form data, it seems that the fine feeds are transformed into CRLF (13+10).

    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.

    0 讨论(0)
提交回复
热议问题