js 字符串中的\n不会换行

解決方案:

var str1=aaaaaaa\nbbbbbbb;

alert(str1); //不换行  ???不知所以然

解决办法:

 while (str1.indexOf("\\n") >= 0) { var str2 = str1.replace("\\n", " \n "); } 

将\n两边各加一个空格就ok了。

alert(str2); //换行

注意: 將"\n" 替換為 “\\n”即可

posted @ 2018-08-23 12:51  侠岚之弋痕夕  阅读(63065)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!