textarea中的空格与换行

当在一个textarea标签中键入一个回车时,实际上会插入2个符号:\n\r
在javascript里, line breaks用\n表示
when you pull text into Javascript, it treats line breaks as the single "\n" value.
  1. In Javascript, new lines are represented by a single "\n" character.
  2. Textarea values might have the character combos "\n\r" in the text box, but once they are pulled into Javascript, "\n\r" becomes JUST "\n".
  3. When replacing out new line characters, treat them as you would any other character. They are not special, they just have special notation.

Ask Ben: Javascript Replace And Multiple Lines / Line Breaks

posted @ 2014-12-10 16:41  alexandra  阅读(283)  评论(0编辑  收藏  举报