replaceText(val) { if (val != null && val != "") { var re1 = new RegExp("<.+?>|&.+?;","g"); //匹配html标签的正则表达式,"g"是搜索匹配多个符合的内容 var msg = val.replace(re1,""); //执行替换成空字符 msg = msg.replace(/\s/g,""); //去掉所有的空格(中文空格、英文空格都会被替换) msg = msg.replace(/[\r\n]/g,""); //去掉所有的换行符 return msg } else return '' } var html =
`<p> </p >
<p> </p >
<p> </p >
<p> </p >
<p> </p >`;
var newHtml = replaceText(html)
标签:val,js,空格,var,html,nbsp,msg,换行符 From: https://www.cnblogs.com/xchlsl/p/17600752.html