用js中的正则表达式
1: 去掉首尾空格
delHtmlTag: function (str) {
var result = str.replace(/(^\s+)|(\s+$)/g, "");//去掉前后空格
return result
},
去掉全部(首尾和中间)空格:
delHtmlTag: function (str) {
var str= str.replace(/</?[^>]*>/gim, "");//去掉所有的html标记
var result = str.replace(/(^\s+)|(\s+$)/g, "");//去掉前后空格
return result.replace(/\s/g, "");//去除文章中间空格
},
2:在获取字符串的地方调用该方法处理
that.setData({
affiche: that.delHtmlTag(res.data.content.clinicInfo.announcement)
})
其中res.data.content.clinicInfo.announcement是后台返回的数据
这时候affiche就把空格去掉了