日期:2014-05-16  浏览次数:20408 次

如何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/> ");