正则替换换行的问题
function coderstr(str)
{
var s = " ";
if (str.length == 0) return " ";
s = str.replace( " <br> ", "\n ");
s = s.replace( " <br> ", "\n ");
s=s.replace( " <BR> ", "\n ");
return s;
}
如果字符串内有一个 <br> 或 <BR> 就不会有问题,可是如果当连续的 <br> 或 <BR> 出现时,就会只替换第一个.请会的朋友指点一下.谢谢了
------解决方案-------------------- <script language=javascript>
function coderstr(str)
{
var s = " ";
if (str.length == 0) return " ";
s = str.replace(/ <br(\/?)> /ig, "\n ");
return s;
}
alert(coderstr( "asdasd <br/> sdf <br/> asdasd "))
</script>
------解决方案--------------------function coderstr(str)
{
if (str.length == 0) return " ";
re=/\ <br\/\> /gi;
return str.replace(re, "\n ");;
}