最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序rich-text富文本用法實例分析

 更新時間:2019年05月20日 09:52:33   作者:我叫陳小皮。  
這篇文章主要介紹了微信小程序rich-text富文本用法,結(jié)合實例形式分析了微信小程序rich-text富文本插件的功能、用法及相關(guān)操作注意事項,需要的朋友可以參考下

本文實例講述了微信小程序rich-text富文本用法。分享給大家供大家參考,具體如下:

rich-text是一個新增的微信小程序插件,從基礎(chǔ)庫1.4.0開始,低版本需要做兼容處理

nodes屬性可為Array和String類型,但推薦使用Array.由于String類型最終也會轉(zhuǎn)為Array類型

nodes分為支持兩種節(jié)點,分別為元素節(jié)點(type=node ,默認為元素節(jié)點)文本節(jié)點(type=text)

元素節(jié)點

name 標簽名 String 支持部分受信任的HTML節(jié)點
attrs 屬性 Object 支持部分受信任的屬性,遵循Pascal命名法
children 子節(jié)點列表 Array 結(jié)構(gòu)和nodes一致

<!-- rich-text.wxml -->
<rich-text nodes="{{nodes}}" bindtap="tap"></rich-text>
<!--{{nodes}}其中的變量名與data中名字相同-->
<!--支持默認事件tap、touchstart、touchmove、touchcancel、touchend和longtap-->

// rich-text.js
Page({
 data: {
 nodes: [{
 name: 'div',
 attrs: {
 class: 'div_class',
 style: 'width : 100px; height : 100px; color: red;'
 },
 children: [{
 type: 'text',
 text: 'Hello&nbsp;World!'
 }]
 }]
 },
 tap() {
 console.log('tap')
 }
})

如果頁面中存在多個富文本,富文本中存在多個孩子,請看下例:

<!-- rich-text.wxml -->
<rich-text nodes="{{nodes}}"></rich-text>
<rich-text nodes="{{nodes1}}"></rich-text>

// rich-text.js
Page({
 data: {
 nodes: [{
 name: 'div',
 attrs: {
 class: 'div_class',
 style: 'width : 100px; height : 100px; color: red;'
 },
 children: [{
 type: 'text',
 text: 'Hello&nbsp;World!'
 }]
 }],
 nodes1: [{
 name: 'p',
 attrs: {
 class: 'p_class',
 style: 'text-align : center; color: green;'
 },
 children: [{
 type: 'text',
 text: '我是p標簽!!!'
 },{
 name: "span",
 attrs: {
  style: "color:red",
  class: "span_class"
 },
 children: [{
  type: "text",
  text: '我是span標簽,哈哈哈哈'
 }]
 }]
 }]
 },
})

文本節(jié)點

text 文本 String 支持entities

<!-- rich-text.wxml -->
<rich-text nodes="{{nodes}}"></rich-text>

// rich-text.js
Page({
 data: {
 nodes: "我是文本節(jié)點,意外不?"
 },
})

注意:

  • 全局支持class和style屬性,不支持id屬性。
  • nodes 不推薦使用 String 類型,性能會有所下降
  • rich-text 組件內(nèi)屏蔽所有節(jié)點的事件。
  • name 屬性大小寫不敏感
  • 如果使用了不受信任的HTML節(jié)點,該節(jié)點及其所有子節(jié)點將會被移除,受信任的html節(jié)點請看官方文檔
  • img 標簽僅支持網(wǎng)絡(luò)圖片

希望本文所述對大家微信小程序開發(fā)有所幫助。

相關(guān)文章

最新評論

吴忠市| 图们市| 腾冲县| 山丹县| 岑巩县| 潍坊市| 商洛市| 西昌市| 河津市| 五指山市| 云阳县| 松阳县| 渝中区| 新泰市| 彝良县| 印江| 慈溪市| 邛崃市| 阜康市| 宁晋县| 新巴尔虎左旗| 邢台市| 东丰县| 南陵县| 遂川县| 广丰县| 周宁县| 巩义市| 卢氏县| 方城县| 博爱县| 永嘉县| 调兵山市| 根河市| 乌拉特中旗| 阜康市| 班戈县| 沙湾县| 柳州市| 弋阳县| 翁牛特旗|