当前位置: 代码迷 >> JavaScript >> 怎么replace掉回车
  详细解决方案

怎么replace掉回车

热度:301   发布时间:2012-03-07 09:13:51.0
如何replace掉回车
在一个textarea里,如何将回车全部替换成 <bt> ,我是这样的:var   str=document.form1.text1.value.replace(String.fromCharCode(13), " <br> "),可是如果要把两个以上的回车替换掉该怎么做,我试过:str=document.form1.text1.value.replace(/[String.fromCharCode(13)]/g, " <br> "),好象不行,不知道是不是哪里错了?

------解决方案--------------------
str=document.form1.text1.value.replace(/[\r\n]{4,}/g, " <br/> ");
------解决方案--------------------
str=document.form1.text1.value.replace(/[\r\n]+}/g, " <br/> ");
  相关解决方案