您现在的位置是:首页 > 电脑技术查询 > web开发

怎么replace掉回车

编辑:chaxungu时间:2022-10-02 23:22:30分类:web开发

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