js修改一段文字中數字的樣式(顏色)
//給一段文字中數字添加顏色
numberToBule:function(str){
var re = /(\d+)/g;
var newstr =str.replace(re, "<span style='color: #0080FF;font-size:14px;'>$1</span>");
//console.log(newstr);
this.setData({
"subInfo.remarks":newstr
});
},
上面是微信小程序的代碼,注意在微信小程序中需要使用富文本標簽:rich-text
wxml
<rich-text nodes="{{subInfo.remarks}}" class="remark-text"></rich-text>
最后給個效果圖