【发布时间】:2020-01-04 05:53:48
【问题描述】:
如果我将textarea 的值设置为"123456\r123" 并调用document.getElementById('myTextarea').value.indexOf("\n"),它会返回6,这是换行符的位置;但是为什么不返回-1,因为字符串中没有\n?
【问题讨论】:
-
你可以从这个 SO stackoverflow.com/questions/10376179/n-t-r-0-is-true" 链接得到你的答案
-
谢谢,例如
+"\n" == +"\r"。但似乎indexOf正在将字符/字符串作为数字进行比较......虽然它正在寻找字符串中的字符串?! -
因为我们还有
"\n" != "\r"
标签: javascript regex textarea newline