html和小程序的常用标签的一些对应关系

简介:微信小程序的wxml和html写法很是相似,但是有些标签和html不同,本文主要介绍了微信小程序一些常用标签与html5的对应关系.

-html--小程序-
-<div></div>--<view></view>-
-<i class="icon">-- <view></view>-
<h1></h1>...<h6></h6><p></p><span></span><view></view>
<i class="icon"><icon></icon>
<iput type="text"> <iput type="checkbox"><iput type="radio"><iput type="file"><input/><checkbox/><radio/><view bindtab="chooseImage">
<a href="#"></a><navigator url="#" redirect></navigator >
<img src=""><image src="" ></image >

参考地址(源地址)
https://blog.csdn.net/tianxintiandisheng/article/details/82464324

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微信小程序中没有直接支持的v-html指令,但你可以通过使用rich-text组件来实现类似的效果。rich-text组件可以渲染带有HTML标记的文本内容。 首先,在你的小程序页面中引入rich-text组件: ```xml <rich-text nodes="{{content}}"></rich-text> ``` 然后,在对应的Page的JS文件中,将HTML内容转换为nodes数组: ```javascript Page({ data: { content: [], }, onLoad: function () { // 假设你的HTML内容存储在变量htmlContent中 const nodes = this.convertHtmlToNodes(htmlContent); this.setData({ content: nodes, }); }, convertHtmlToNodes: function (html) { // 使用正则表达式将HTML内容转换为nodes数组 // 这里可以自定义转换规则,根据需要进行处理 // 下面是一个简单示例,只处理了部分常用标签 const tagRegex = /<(\/?)(\w+)([^>]*)>/g; const attrRegex = /(\w+)=["']([^"']*)["']/g; const nodes = []; let match; let lastIndex = 0; while ((match = tagRegex.exec(html)) !== null) { const [fullMatch, isClosingTag, tagName, attrs] = match; const attributes = {}; let attrMatch; while ((attrMatch = attrRegex.exec(attrs)) !== null) { const [attrFullMatch, attrName, attrValue] = attrMatch; attributes[attrName] = attrValue; } const node = { type: isClosingTag ? 'node' : 'element', name: tagName, attrs: attributes, children: [], }; if (isClosingTag) { let parentIndex = nodes.length - 1; while (parentIndex >= 0) { const parent = nodes[parentIndex]; if (parent.type === 'element' && parent.name === tagName) { parentIndex--; break; } parentIndex--; } if (parentIndex >= 0) { nodes[parentIndex].children.push(node); } } else { if (lastIndex < match.index) { const textContent = html.slice(lastIndex, match.index); nodes.push({ type: 'text', text: textContent, }); } nodes.push(node); } lastIndex = match.index + fullMatch.length; } if (lastIndex < html.length) { const textContent = html.slice(lastIndex); nodes.push({ type: 'text', text: textContent, }); } return nodes; }, }); ``` 这样就可以在小程序中渲染带有HTML标记的文本内容了。请注意,上述示例只是一个简单的转换方法,如果你的HTML内容比较复杂,可能需要进行更复杂的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值