0
点赞
收藏
分享

微信扫一扫

【小程序】如何对rich-text富文本中的内容进行replace替换(已解决,图文示例)


一、问题

后台传过来的富文本是:

img图片style="",没有样式

【小程序】如何对rich-text富文本中的内容进行replace替换(已解决,图文示例)_正则表达式

 

<p>
<span style="font-family: 仿宋_GB23;"></span>
</p>
<p>
<img src="http://site.kerzd.cn/Content/ueditor1_4_3-utf8-net/net/upload/image/20221230/6380800848463290233069237.jpg" style=""/>
</p>
<p>
<img src="http://site.kerzd.cn/Content/ueditor1_4_3-utf8-net/net/upload/image/20221230/6380800848550791681969888.jpg" style=""/>
</p>
<p>
<span style="font-family: 仿宋_GB23;"></span><br/>
</p>

2、解决

通过正则表达式替换aaa.replace(/被替换内容/g,"替换成的内容")

this.setData({
productDetail: (this.data.productDetail).replace(/img src/g, "img style=\"width:100%\" src")
})
this.setData({
productDetail: (this.data.productDetail).replace(/ style=""/g, "")
})

举报

相关推荐

0 条评论