【发布时间】:2019-02-28 14:33:53
【问题描述】:
从多行文本区域返回的这个“↵”字符是什么?我所有的搜索(和原因)都表明它应该是一个换行符,例如\n。
但是当x.time 设置为多行textarea 的内容时,这不起作用:
> x
{time: "one↵two↵three↵"}
> x.time
"one↵two↵three↵"
> x.time.replace(/(\r\n|\n|\r)/gm, "___")
"one↵two↵three↵"
虽然这有效:
> x.time.replace(/↵/g,"___")
"one___two___three___"
【问题讨论】:
-
一个unicode字符?
-
因为您在字面上使用它...它没有显示在换行符的位置,您使用的是literal Unicode value。显然第二个 sn-p 会起作用。
-
那么为什么
x.time.replace(/\n/gm, "___")不起作用?
标签: javascript google-chrome newline