用js中的正則表達(dá)式
1: 去掉首尾空格
delHtmlTag: function (str) {
var result = str.replace(/(^\s+)|(\s+$)/g, "");//去掉前后空格
return result
},
去掉全部(首尾和中間)空格:
delHtmlTag: function (str) {
var str= str.replace(/</?[^>]*>/gim, "");//去掉所有的html標(biāo)記
var result = str.replace(/(^\s+)|(\s+$)/g, "");//去掉前后空格
return result.replace(/\s/g, "");//去除文章中間空格
},
2:在獲取字符串的地方調(diào)用該方法處理
that.setData({
affiche: that.delHtmlTag(res.data.content.clinicInfo.announcement)
})
其中res.data.content.clinicInfo.announcement是后臺返回的數(shù)據(jù)
這時候affiche就把空格去掉了