微信小程序处理html富文本展示

首先来看下最终效果

可以在页面上展示段落,图片,加粗文字等各种网页上的富文本操作

更多细节可以在这个小程序上查看

 

话不多说,往下看

js代码如下

var html = '<p>12321311<span style="text-decoration: underline;">321321321321<span style="text-decoration: line-through;">3213213213213231asdasdasda<img src="http://sgsource.sougewang.com/image/know/30b64859b849008ca2cb83bd3934ea4c.png" /><video controls="controls" width="300" height="150"><source src="http://sgsource.sougewang.com/video/know/4c83a1703c5f8a82efc26519be342748.mp4" type="video/mp4" /></video></span></span></p>'
data: {
    htmlSnip:html.replace(/<section/g, '<div').replace(/\/section>/g, '/div>'),
  },

wxml部分

<rich-text nodes="{{htmlSnip}}"></rich-text>

大功告成,快去试一下吧

标签rich-text就可以处理大部分html标签

如果有什么不明白的可以留言哦

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值